stl string 函数
append() is a library function of <string> header, it is used to append the extra characters/text in the string.
append()是<string>标头的库函数,用于在字符串中附加多余的字符/文本。
Syntax:
句法:
string& append(const string& substr);
Here,
这里,
string& is the reference to the string in which we are adding the extra characters.
string&是对要在其中添加额外字符的字符串的引用。
substr is the extra set of character/sub-string to be appended.
substr是要附加的字符/子字符串的额外集合。
There are some other variations (function overloading) of the function that are going to be used in the program.
程序中还将使用该函数的其他一些变体(函数重载)。
Program:
程序:
#include <iostream>
#include <string>
using namespace std;
int main ()
{
string str = "Hello";
string str2 = " ## ";
string str3 = "www.google.com";
cout<<str<<endl;
//append text at the end
str.append (" world");
cout<<str<<endl;
//append 'str2'
str.append (str2) ;
cout<<str<<endl;
//append space
str.append (" ");
//append 'google' from str3
str.append (str3.begin () +4, str3.begin () +10) ;
cout<<str<<endl;
return 0;
}
Output
输出量
HelloHello worldHello world ## Hello world ## google
翻译自: https://www.includehelp.com/stl/appending-text-to-the-string-using-string-append-function.aspx
stl string 函数