C语言的字符串 C++的字符串
头文件:
#include<string.h> //c
#include<string> //C++
#include<cstring> //C++
比较string的大小
两个string对象相加
使用字符串对象来存放字符串
两个string对象相加
string str = "Hello,";
string phrase = "world ";string s = str + phrase;
str += phrase;//相当于str = str + phrasecout << s << endl;
cout << str << endl;
#include<string>
#include<string.h> // 或
#include<cstring>
using namespace std;
int main()
{char str[] = ["tulun}; // str 是数组,存储字符int len = strlen(str);string sl = "tulun"; // 字符串for (int i = 0; i < len; ++i){cout << str[i];}// s1.1ength(); // s1.size();for (int i = 0; i < s1.size(); ++i){cout << sl[i];}cout << s1 << end1; s1 = "he11o";cout << s1 << end1; s1 += "tulun";cout << s1 << end1;cin >> s1; // new data // 空格为中止符cout<<s<<end1;
}