c++ string构造函数学习
#include <iostream>
#include <string>
using namespace std;
int main()
{
string a1;
cout << a1<< endl;
string s2(5,'a');
cout << s2 << endl;
string s3(s2);
s3 = "opper";
cout << s3 << endl;
string s4(s3.begin(),s3.begin()+s3.size()/2);
cout << s4 << endl;
char *cp = "hello";
char c_array[] = "world";
char no_null[] = {'H','i','j','a','v','a'};
string str1(cp);
cout << str1 << endl;
string str2(c_array,3);
cout << str2 << endl;
string str3(c_array+2,3);
cout << str3 << endl;
string str4(no_null,3);
cout << str4 << endl;
string str5(s2,2);
cout << str5 << endl;
string str6(s2,0,3);
cout << str6 << endl;
string str7(s2,0,8);
cout << str7 << endl;
system("pause");
return 0;
}
============================================
aaaaa
opper
op
hello
wor
rld
Hij
aaa
aaa
aaaaa
请按任意键继续. . .