1 #include <iostream>
 2 #include<string>//调用string函数库
 3 using namespace std;
 4 int main()
 5 {
 6     string s1, s2;//定义两个string类型的变量s1 s2
 7     s1 = "c++程序";//对s1变量进行初始化
 8     s2 = s1;//对s2变量初始化等于s1
 9     string s3;//定义一个string变量
10     cout << "s3=" << s3 << endl;//直接输出变量s3,但是s3的值为空,因此只输出“s3=”
11     s3 = s1 + s2;//初始化s3
12     cout << s1 + s2 << endl;
13     cout << "s3=" << s3 << endl;
14     bool b = s1 < s3;//定义一个布尔类型变量 b 并且用来判断s1<s3,“真”和“假”,是用 0 和非 0 来代表
15     cout << "bool=" << b << endl;
16     char c = s1[2];//定义字符串类型 c 并取s1的第三个 即s1[0,1,2]中的s1[c,+,+]
17     cout << "c=" << c << endl;
18     cout << s1[2] << endl;
19     char arrstr[] = "Hello";
20     s3 = s1 + arrstr;
21     cout << s3 << endl;
22     system("pause");
23 }

 

posted on 2022-01-21 16:35  咫尺流云  阅读(102)  评论(0)    收藏  举报