• 코드:
​x
 
1
#include <iostream>
2
#include <iterator>
3
#include <vector>
4
using namespace std;
5
​
6
int main(void)
7
{
8
    vector<int> vc = {10, 20, 30};  // vector 객체의 선언 및 초기화 
9
    cout << "현재 벡터의 크기는 " << vc.size() << "입니다." << endl;
10
​
11
    vc.push_back(40);               // vector 요소의 추가 
12
    cout << "현재 벡터의 크기는 " << vc.size() << "입니다." << endl;
13
    cout << "현재 벡터의 네 번째 요소는 " << vc[3] << "입니다." << endl;
14
    
15
    cout << "현재 벡터의 모든 요소는 다음과 같습니다 :" << endl;
16
    copy(vc.begin(), vc.end(), ostream_iterator<int>(cout, " "));
17
    return 0;
18
}
표준입력 & 실행옵션