push_back

push_back

push_back是程式語言裡面的一個函式名。如c++中的vector頭檔案裡面就有這個push_back函式,在vector類中作用為在vector尾部加入一個數據。

基本介紹

  • 外文名:push_back
  • 隸屬:stl 容器
  • 作用:用於在後面添加一項。
  • 算法語言:c++
函式名,函式原型,舉例,

函式名

string中也有這個函式,作用是字元串之後插入一個字元。

函式原型

void push_back(value _type _Ch);
參數
_Ch --> The character to be added to the end of the string.
在vector類中:
void push_back(const _Ty &_X){insert(end(), _X);}
在vector<_Bool, _Bool_allocator>類中:
void push_back(const bool _X){insert(end(), _X);}

舉例

//basic_string_push_back.cpp//compilewith:/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 char acter-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;}
輸出:
The original string str1 is:abcThe last character-letter of the modified str1 is now:cThe modified string str1 is:abcd
註:VC6.0中未通過,string中無push_back的定義。

相關詞條

熱門詞條

聯絡我們