C++ 容器 string类
一、string类的构造函数
1 默认构造 string s1;
2 拷贝构造 string s2(s1);
3 有参构造 string s3(“aaa”);
4 两个参数有参构造 string s4(3,‘c’);
// string类的构造函数
string s1; //默认构造
string s2(s1); //拷贝构造
string s3("aaa"); //有参构造
string s4(3, 'c'); //两个参数有参构造
cout << "字符串s1为:"<<s1 << endl;
cout <<"字符串s2为:"<< s2 << endl;
cout <<"字符串s3为:"<< s3 << endl;
cout <<"字符串s4为:"<< s4 << endl;
字符串s1为:
字符串s2为:
字符串s3为:aaa
字符串s4为:ccc
二、string类的赋值操作
1、string& assign(const char *s,int n); 把字符串s的前n个字符串赋给当前的字符串
2、string& assign(const string &s,int start,int n); 将s从start开始n个字符赋值给字符串
//string类的赋值操作
string s5;
//string& assign(const char *s,int n); 把字符串s的前n个字符赋给当前的字符串
s5.assign("asddfsdsgdsgd", 8);
cout << "s5=" << s5 << endl;
//string& assign(const string &s,int start,int n); 将s从start开始n个字符赋值给字符串(从0开始计算)
string s6 =</