很不错的网址:http://www.cplusplus.com/
1、strcmp函数的功能是比较str1和str2这两个字符串的大小,规则是从左往右比较两个字符串对应位置的ASC2码值的大小,两个对应位上的字符不相同时,或者遇到字符串结束符(\0),则返回结果。
当str1<str2时,返回负数;当str1=str2时,返回0;当str1>str2时,返回正数。
2、以下做法是错误的,因为strcmp的参数必须是char *类型的,而a,a[0]不是指针类型的。
string a("abc");
string b("cnbvb");
strcmp(a,b); //错误
strcmp(a[0],b[0]); //错误
正确的做法如下,必须先将string类型的对象a,b用c_str()方法转化为字符串。
//姓名排序
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
using namespace std;
struct man
{