C++ 벡터 슬라이싱

1 개요[ | ]

C++ 벡터 슬라이싱
#include <iostream>
#include <vector>
using namespace std;

int main() {
    vector<int> v = {100,200,300,400,500,600,700};
    vector<int> v2;
    v2 = vector<int>(v.begin()+0, v.begin()+3);
    for(auto el: v2) cout << el << ' '; cout << '\n'; // 100 200 300 
    v2 = vector<int>(v.begin(), v.begin()+5);
    for(auto el: v2) cout << el << ' '; cout << '\n'; // 100 200 300 400 500 
    v2 = vector<int>(v.begin()+3, v.end());
    for(auto el: v2) cout << el << ' '; cout << '\n'; // 400 500 600 700 
}

2 같이 보기[ | ]

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