C++ 벡터 insert()

1 개요[ | ]

C++ 벡터 insert()
#include <iostream>
#include <vector>
using namespace std;
int main ()
{
  vector<int> v = {1,2,3};
  
  v.insert(v.begin(), 10);
  for(int el: v) cout << el << ' '; // 10 1 2 3
  cout << endl;
  
  v.insert(v.end(), 3, 100);
  for(int el: v) cout << el << ' '; // 10 1 2 3 100 100 100 
  cout << endl;
}
#include <iostream>
#include <vector>
using namespace std;
int main ()
{
  vector<int> v (3,100);
  vector<int>::iterator it;

  it = v.begin();
  it = v.insert ( it , 200 );

  v.insert (it,2,300);

  it = v.begin();

  vector<int> w (2,400);
  v.insert (it+2,w.begin(),w.end());

  int arr [] = { 501,502,503 };
  v.insert (v.begin(), arr, arr+3);

  for (it=v.begin(); it<v.end(); it++) {
    cout << *it << ' ';
  }
}

2 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}