1. #include<iostream>
    2. #include<string>
    3. using namespace std;
    4. //string的构造函数
    5. /*
    6. string(); // 创建一个空的字符串,例如:string str;
    7. string(const char * s); //使用字符串s初始化
    8. string(const string & str); //使用一个string对象初始化另一个string对象
    9. string(int n,char c); //使用n个字符c初始化
    10. */
    11. void test01()
    12. {
    13. string s1; //默认构造
    14. const char* str = "hello world";
    15. string s2(str);
    16. cout << "s2 = " << s2 << endl;
    17. string s3(s2);
    18. cout << "s3 = " << s3 << endl;
    19. string s4(10, 'a');
    20. cout << "s4 = " << s4 << endl;
    21. }
    22. int main(void)
    23. {
    24. test01();
    25. system("pause");
    26. return 0;
    27. }