deque::push_front

将元素添加到、向量、双端队列的开头。

void push_front(
   const Type& _Val
);
void push_front(
   Type&& _Val
);

参数

Parameter

说明

_Val

元素添加到、向量、双端队列的开头。

备注

如果引发了异常,、向量、双端队列保持不变,并且异常来重新引发。

示例

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

int main( ) 
{
   using namespace std;
   deque <int> c1;
   
   c1.push_front( 1 );
   if ( c1.size( ) != 0 )
      cout << "First element: " << c1.front( ) << endl;

   c1.push_front( 2 );
   if ( c1.size( ) != 0 )
      cout << "New first element: " << c1.front( ) << endl;

// move initialize a deque of strings
   deque <string> c2;
   string str("a");

   c2.push_front( move( str ) );
   cout << "Moved first element: " << c2.front( ) << endl;
}
  

要求

标头: <deque>

命名空间: std

请参见

参考

deque Class

deque::push_front 和 deque::pop_front

标准模板库