How to split vector according to indices given in another vector?
How to split vector according to indices given in another vector? I have a source std::vector<double> , which I'd like to split according to indices contained in std::vector<int> . The split is inclusive, and start of next slice should start where previous left off, starting from start of the source vector. std::vector<double> std::vector<int> For example: { 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9 } -> source {2, 4, 7 } -> split indices and after applying the function it should produce: {1.1, 2.2, 3.3} {4.4, 5.5} {6.6, 7.7, 8.8} I have this which won't give me the third vector and so on: vector<double> nets{ 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9 }; vector<int> ends{2, 4, 7 }; vector<vector<double>> periodnumbers; vector<double> numbers; for (int i = 0; i < nets.size(); i++) { double temp; temp = nets[i]; numbers.push_back(temp); for (int j = 0; j < ends.size(); j++) { if (i ...
