将元素添加到列表的末尾。
void push_back(
void push_back(
Type&& _Val
);
参数
Parameter |
说明 |
_Val |
元素添加到列表的末尾。 |
备注
如果引发了异常,列表未更改,并且异常来重新引发。
示例
// list_push_back.cpp
// compile with: /EHsc
#include <list>
#include <iostream>
#include <string>
int main( )
{
using namespace std;
list <int> c1;
c1.push_back( 1 );
if ( c1.size( ) != 0 )
cout << "Last element: " << c1.back( ) << endl;
c1.push_back( 2 );
if ( c1.size( ) != 0 )
cout << "New last element: " << c1.back( ) << endl;
// move initialize a list of strings
list <string> c2;
string str("a");
c2.push_back( move( str ) );
cout << "Moved first element: " << c2.back( ) << endl;
}
要求
标头: <list>
命名空间: std