C++ 字串庫 - append



描述

它透過在當前值的末尾追加額外的字元來擴充套件字串。

宣告

以下是 std::string::append 的宣告。

string& append (const string& str);

C++11

string& append (const string& str);

C++14

string& append (const string& str);

引數

  • str − 它是一個字串物件。

  • c − 它是一個字元物件。

返回值

它返回 *this。

異常

如果丟擲異常,字串不會發生任何更改。

示例

以下為 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
廣告