I have the usual vector of integer values 'vector v'. It is filled with values by the user, and the dimension of the vector after filling will be exactly divisible by 6. I need to divide this vector into as many vectors as there are groups of 6 numbers each. For example, if the user entered 12 numbers, then the vector should be divided into 2 vectors of 6 numbers each; if 24 numbers, then on 4 vectors, etc. Tell me please, I was searching, but I can’t find (The difficulty is that even after the user has entered everything, I can determine how many vectors I need by writing "a = v.size () / 6", but I don’t know how to break this vector into this number in a loop.
#include<iostream> #include<vector> using namespace std; int main() { int a; vector<int> v1; for (cin; ; ) { //получение всех значений cin >> a; if (a == -1) { break; } v1.push_back(a); } int size = v1.size() / 6; //количество векторов, на которые нужно разбить вектор for (int i = 0; i < size; i++) { //разбиение вектора } return 0; }
vector<vector<int>>
good or not? - Harry