C++ string append()添加文本
使用append()添加文本常用方法:
直接添加另一个完整的字符串:
如str1.append(str2);
添加另一个字符串的某一段子串:
如str1.append(str2, 11, 7);
添加几个相同的字符:
如str1.append(5, ‘.’);
注意,个数在前字符在后.上面的代码意思为在str1后面添加5个”.”.
//======================================== #include<iostream> 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<<str1<<endl; cout<<str3<<endl; cout<<str4<<endl; system("pause"); return 0; } //========================================
运行结果为
I like C++,I like the world. Hello World. Hi.....
以上这篇对C++ string append方法的常用用法详解就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持<计算机技术网(www.ctvol.com)!!>。
—-想了解对C++ string append方法的常用用法详解分享!全部内容且更多的C语言教程关注<计算机技术网(www.ctvol.com)!!>
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。
ctvol管理联系方式QQ:251552304
本文章地址:https://www.ctvol.com/c-cdevelopment/482382.html