deque::insert (STL Samples)
사용 하는 방법을 보여 줍니다 있는 deque::insert Visual C++에서 표준 템플릿 라이브러리 (STL) 함수입니다.
iterator insert(
iterator Iter,
const T& x = T( )
);
void insert(
iterator Iter,
size_type n,
const T& x
);
void insert(
iterator Iter,
const_iterator First,
const_iterator Last
);
설명
[!참고]
프로토타입에 클래스/매개 변수 이름은 헤더 파일에서 버전이 일치 하지 않습니다.일부 가독성을 높이기 위해 수정 되었습니다.
각 함수 포인터가 가리키는 요소 뒤 나머지 피연산자를 통해 지정 된 시퀀스를 삽입 합니다. Iter 의 컨테이너입니다.멤버 함수는 첫 번째 값을 가진 단일 요소를 삽입 합니다. x 와 새로 삽입 된 요소를 가리키는 반복기를 반환 합니다.두 번째 멤버 함수는 반복 된 삽입 n 값의 요소를 x.세 번째 멤버 함수는 시퀀스 삽입 [First, Last).
예제
// insert.cpp
// compile with: /EHsc
#include <iostream>
#include <deque>
using namespace std;
typedef deque<char > CHARDEQUE;
void print_contents (CHARDEQUE deque);
int main()
{
//create a with 3 A's
CHARDEQUE a(3,'A');
//create b with 2 B's.
CHARDEQUE b(2,'B');
//print out the contents
print_contents (a);
print_contents (b);
//insert 'X' to the beginning of a
a.insert(a.begin(),'X');
print_contents (a);
//insert 'Y' to the end of a
a.insert(a.end(),'Y');
print_contents (a);
//inset 3 'Z's to one item before the end of a
a.insert(a.end()-1,3,'Z');
print_contents (a);
//insert to the end of a from b
a.insert(a.end(),b.begin(),b.end());
print_contents (a);
}
//function to print the contents of deque
void print_contents (CHARDEQUE deque)
{
CHARDEQUE::iterator pdeque;
cout <<"The output is: ";
for(pdeque = deque.begin();
pdeque != deque.end();
pdeque++)
{
cout << *pdeque <<" " ;
}
cout<<endl;
}
Output
The output is: A A A
The output is: B B
The output is: X A A A
The output is: X A A A Y
The output is: X A A A Z Z Z Y
The output is: X A A A Z Z Z Y B B
요구 사항
헤더: <deque>