C++ String Library - append



Description

It extends the string by appending additional characters at the end of its current value.

Declaration

Following is the declaration for std::string::append.

string& append (const string& str);

C++11

string& append (const string& str);

C++14

string& append (const string& str);

Parameters

  • str − It is a string object.

  • c − It is a character object.

Return Value

It returns *this.

Exceptions

if an exception is thrown, there are no changes in the string.

Example

In below example for 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.....
string.htm
Advertisements