1、string基本概念
#include<iostream>
using namespace std;
#include<string>
#include<vector>
#include<algorithm>
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;
}
2、赋值操作
#include<iostream>
using namespace std;
#include<string>
#include<vector>
#include<algorithm>
void test01()
{
string str1;
str1 = "hello world";
string str2;
str2 = str1;
string str3;
str3 = 'a';
string str4;
str4.assign("hello world");
string str5;
str5.assign("hello", 3);
}
int main()
{
test01();
system("pause");
return 0;
}
3、string字符串拼接