append
描述 (Description)
它通过在其当前值的末尾附加附加字符来扩展字符串。
声明 (Declaration)
以下是std :: string :: append的声明。
string& append (const string& str);
C++11
string& append (const string& str);
C++14
string& append (const string& str);
参数 (Parameters)
str - 它是一个字符串对象。
c - 这是一个角色对象。
返回值 (Return Value)
它返回* this。
异常 (Exceptions)
如果抛出异常,则字符串中没有变化。
例子 (Example)
在下面的示例中为std :: string :: append。
#include <iostream>
#include <string>
int main () {
std::string str;
std::string str2="Writing ";
std::string str3="print 10 and then 5 more";
str.append(str2);
str.append(str3,6,3);
str.append("dots are cool",5);
str.append("here: ");
str.append(10u,'.');
str.append(str3.begin()+8,str3.end());
str.append<int>(5,0x2E);
std::cout << str << '\n';
return 0;
}
Writing 10 dots here: .......... and then 5 more.....