#include <iostream>
#include <cstring> //strcmp、strcpy、strncpy函数所在头文件
using namespace std;
int main()
{
char *str = "you爱我haishi他";
cout << "strlen(str)=" << strlen(str) <<" sizeof(str)=" << sizeof(str) << endl;
char *str1 = new char[10];
strcpy(str1,str);
cout << "str1 = " << str1 << endl;
char *str2 = new char[10];
strncpy(str2,str + 3,5);
cout << "str2 = " << str2 << endl;
char *a = "a";
char *c = "b";
int i = strcmp(a,c);
int j = strcmp("a","a");
cout << "strcmp(a,c) = "<< i <<"j = "<< j<< endl;
delete []str1;
delete []str2;
return 0;
}
* 汉字字符范围为ASCII范围之外,即非0~127范围;且每个汉字字符占2字节。
* strcmp(const char*,const char*),比如strcmp(“a”,”b”) = -1,strcmp(“c”,”b”) = 1,strcmp(“z”,”z”) = 0。将它们放在if(…)中,凡是非0的值都为真。