append()是标头的库函数,用于在字符串中附加多余的字符/文本。
语法:string& append(const string& substr);
这里,string&是对要在其中添加额外字符的字符串的引用。
substr是要附加的字符/子字符串的额外集合。
程序中还将使用该函数的其他一些变体(函数重载)。
程序:#include
#include
using namespace std;
int main ()
{
string str = "Hello";
string str2 = " ## ";
string str3 = "www.google.com";
cout<
//在末尾附加文字
str.append (" world");
cout<
//附加'str2'
str.append (str2) ;
cout<
//追加空间
str.append (" ");
//从str3附加'google'
str.append (str3.begin () +4, str3.begin () +10) ;
cout<
return 0;
}
输出结果Hello
Hello world
Hello world ##
Hello world ## google