zl程序教程

您现在的位置是:首页 >  工具

当前栏目

string容器03之string字符串拼接

容器 string 字符串 03 拼接
2023-09-14 09:02:34 时间

string字符串拼接

在这里插入图片描述

#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;
}

在这里插入图片描述