/*********************************************************************************
Copyright(C),Your Company
Author: KimChow
Date: 2021-04-17
Description:C++ 字符串拼接
Others:
**********************************************************************************/
#include <iostream>
using namespace std;
int main()
{
string s1 = "Hello ";
string s2 = "World!";
s1.append(s2);
cout << s1 << endl;
string s3 = "Hello ";
string s4 = "Hello World!";
s3.append(s4, 6, 5);//从s4的第六位(0位开始数)开始的连续5位--World,即s3+"World"
cout << s3 << endl;//
string s5 = "Hello ";
//将10个A拼接到字符串s5的后面
s5.append(10, 'A');
cout << s5 << endl;
string s6 = s1 + s2;
cout << s6 << endl;
return 0;
}
C++ 字符串拼接
于 2022-04-17 09:07:28 首次发布