c语⾔append,对C++stringappend⽅法的常⽤⽤法详解C++ string append()添加⽂本
使⽤append()添加⽂本常⽤⽅法:
直接添加另⼀个完整的字符串:
如str1.append(str2);
添加另⼀个字符串的某⼀段⼦串:
如str1.append(str2, 11, 7);
添加⼏个相同的字符:
如str1.append(5, '.');
注意,个数在前字符在后.上⾯的代码意思为在str1后⾯添加5个".".
//========================================
#include
using namespace std;
//========================================
int main()
{
string str1="I like C++";
string str2=",I like the world.";
string str3="Hello";
string str4("Hi");
//====================================
str1.append(str2);
str3.append(str2, 11, 7);
str4.append(5, '.');
//====================================
cout<
cout<
c++string类型
cout<
system("pause");
return 0;
}
//========================================
运⾏结果为
I like C++,I like the world.

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。