string的构造函数

#include<iostream
#include<string
#include<algorithm
#include<vector
using namespace std;

//string是一个类,内部封装了char*,管理这个字符串
//string 的构造函数

/*
string();
string(const char* str)//使用一个string初始化另外一个string对象

string(int n,char c)//使用n个字符c初始化
*/
void test01() {

string s1;//默认构造


const char * str = "hello world";

string s2(str);

cout << "s2 = " << s2 << endl;

string s3(s2);  //拷贝函数
cout << "s3 = " << s3 << endl;

}

int main() {

test01();

system("pause");
return 0;

}


版权声明:本文为qq_36767550原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。