string字符串拼接
功能描述:
实现在字符串末尾拼接字符串
函数原型:
代码如下:
#include <iostream>
using namespace std;
#include <cstring>//string字符串拼接
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;str3.append(" game abcde", 5);cout << "str3 = " << str3 << endl;str3.append(str2);cout << "str3 = " << str3 << endl;str3.append(str2, 0, 3);//0,3 表示从第0个位置开始,截取3个的意思 只截取了LOLcout << "str3 = " << str3 << endl;str3.append(str2, 4, 3);//只截取了DNF 参数2 从哪个位置开始截取 参数3 截取字符串个数cout << "str3 = " << str3 << endl;}int main() {test01();return 0;
}