共用方式為


basic_string::push_back

將項目加入至字串的結尾。

void push_back(
    value_type _Ch
);

參數

  • _Ch
    要加入的字元加入至字串的結尾。

備註

成員函式有效地呼叫 插入( 結束, _Ch)。

範例

// basic_string_push_back.cpp
// compile with: /EHsc
#include <string>
#include <iostream>

int main( ) 
{
   using namespace std;
   string str1 ( "abc" );
   basic_string <char>::iterator str_Iter, str1_Iter;

   cout << "The original string str1 is: ";
   for ( str_Iter = str1.begin( ); str_Iter != str1.end( ); str_Iter++ )
      cout << *str_Iter;
   cout << endl;

   // str1.push_back ( 'd' );
   str1_Iter = str1.end ( );
   str1_Iter--;
   cout << "The last character-letter of the modified str1 is now: "
        << *str1_Iter << endl;

   cout << "The modified string str1 is: ";
   for ( str_Iter = str1.begin( ); str_Iter != str1.end( ); str_Iter++ )
      cout << *str_Iter;
   cout << endl;
}
  

需求

標題: <string>

命名空間: std

請參閱

參考

basic_string Class