#include<iostream>
using namespace std;
void test01()
{
string s1;
const char* str = "hello world";
string s2(str);
cout << "s2 = " << s2 << endl;
string s3(s2);
cout << "s3 = " << s3 << endl;
string s4(10, 'a');
cout << "s4 = " << s4 << endl;
}
int main()
{
test01();
system("pause");
return 0;
}
#include<iostream>
using namespace std;
#include<string>
void test01()
{
string str1;
str1 = "hello world";
cout << "str1 = " << str1 << endl;
string str2;
str2 = str1;
cout << "str2 = " << str2 << endl;
string str3;
str3 = 'a';
cout << "str3 =" << str3 << endl;
string str4;
str4.assign("hello C++");
cout << "str4 =" << str4 << endl;
string str5;
str5.assign("hello C++",4);
cout << "str5 =" << str5 << endl;
string str6;
str6.assign(str5);
cout << "str6 =" << str6 << endl;
string str7;
str7.assign(10,'a');
cout << "str7 =" << str7 << endl;
}
int main()
{
test01();
system("pause");
return 0;
}```
```cpp
#include<iostream>
using namespace std;
#include<string>
void test01()
{
string str1 = "我";
str1 += "爱玩游戏";
cout << "str1 = " << str1 << endl;
str1 += ":";
cout << "str1 = " << str1 << endl;
string str2;
str2 = "LOL";
str1 += str2;
cout << "str1 = " << str1 << endl;
string str3 = "I";
str3.append(" love ");
cout << "str3 = " << str3 << endl;
str3.append(" wangcong ",9);
cout << "str3 = " << str3 << endl;
str3.append(str1);
cout << "str3 = " << str3 << endl;
str3.append(str2,1,2);
cout << "str3 = " << str3 << endl;
}
int main()
{
test01();
system("pause");
return 0;
}