成功源于积累----波爸

思想决定高度,行动决定成败!

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

strlen是求可见字符串的长度,不包括结束字符'\n'

sizeof是包括结束字符 '\n’

 

    char man[12] = {"hello world"};
    cout << man << endl;
    cout << "strlen(man):" << strlen(man) << endl; // 11
    cout << "sizeof(man):" << sizeof(man) << endl; // 12

 

char 型字符串是C风格的字符串

C++使用string类,存在std空间中,用using namespace std,或者std::string

定义一个string对象str:

string str;

 

strcmp()用来比较两个字符串是否相等,分别返回 -1,0,1代表第一个字符串小于第二个字符串,0表示相等,1代表大于

 

assign函数就是从一个字符串中取任意字符串给另一个字符串

string str1="bupt";

string str2="a cup";

str1=assign(str2, 3, 1);

cout << str1<< endl; // u

 

strcat(ch1, ch2);合并两个char型字符串,第一个字符串的大小必须够容纳二个字符串大小和

 

posted on 2012-06-23 20:43  沙场醉客  阅读(139)  评论(0编辑  收藏  举报