string容器03之string字符串拼接

2021-03-02 16:56:18 浏览数 (1)

string字符串拼接

代码语言:javascript复制
#include<iostream>
using namespace std;
//string字符串拼接
void test() 
{
	string s1("Good");
	string s2 = " Bye";
	s1  = s2;
	cout << s1 << endl;
	s1  = " The  World";
	cout << s1 << endl;
	s1  = '!';
	cout << s1 << endl;
	//append
	string s3 = ("Hello ");
	s3.append("The ");
	cout << s3 << endl;
	string s4("World ");
	s3.append(s4);
	cout << s3 << endl;
	//注意:如果第一个参数填入string类型字符串,就会拷贝第三个字符后面的字符串
	/*string s5 = "!!!adadas";
	s3.append(s5, 3);*/
	s3.append("!!!  adbasdas", 5);
	cout << s3 << endl;
	string s6 = "I Was So Happy Every Day!";
	s3.append(s6, 9, 16);
	cout << s3 << endl;
}
int main()
{
	test();
	system("pause");
	return 0;
}

0 人点赞