#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
//字符串拼接
void test01()
{
string str1 = "我";
str1 += "爱玩游戏";
cout << "str1 = " << str1 << endl;
str1 += ';';
cout << "str1 = " << str1 << endl;
string str2 = " LOL DNF ";
str1 += str2;
cout << "str1 = " << str1 << endl;
string str3 = "I";
str3.append(" Love ");
cout << "str3 = " << str3 << endl;
//把字符串前n个字符连接到当前字符串结尾
str3.append("game abcdef", 4);
cout << "str3 = " << str3 << endl;
//str3.append(str2);
//cout << "str3 = " << str3 << endl;
//参数2 从哪个位置开始截取,参数3 截取字符个数
str3.append(str2, 4, 4);
cout << "str3 = " << str3 << endl;
}
int main()
{
test01();
system("pause");
return 0;
}
(1)string-字符串拼接
最新推荐文章于 2024-07-20 21:25:18 发布