vector进行片段截取操作
#include <iostream>
#include <vector>
int main() {
std::vector<int> vector{1,2,3,4,5,6,7,8,9};
std::cout << "vectoor: ";
for(auto el : vector) {
std::cout << el << " ";
//截取前4个数
std::vector<int>::const_iterator first1 = vector.begin();
std::vector<int>::const_iterator last1 = vector.begin() + 4;
std::vector<int> cut1_vector(first1, last1);
std::cout << "\ncut1_vector: ";
for(auto el : cut1_vector) {
std::cout << el << " ";
//截取后4个数
std::vector<int>::const_iterator first2 = vector.end() - 4;
std::vector<int>::const_iterator last2 = vector.end();
std::vector<int> cut2_vector(first2, last2);
std::cout << "\ncut2_vector: ";
for(auto el : cut2_vector) {
std::cout << el << " ";
std::cout << "\n";