0

I'd imagine there is a much better way to do this...

vector<double> Model;
//code to fill Model
vector<double> V1;

for(int i = StartModel; i <= EndModel; i++)
                V1.push_back( Model.at(i) );
2
Contributors
3
Replies
4
Views
9 Years
Discussion Span
Last Post by Narue
0

"Much better" is debatable, but you can make use of the constructor that takes an iterator range:

vector<double> V1(Model.begin() + StartModel, Model.begin() + EndModel);
0
V1.insert ( V1.begin(), Model.begin() + StartModel, Model.begin() + EndModel );

Another alternative:

#include <algorithm>
#include <iterator>

std::copy ( Model.begin() + StartModel, Model.begin() + EndModel, std::back_inserter ( V1 ) );
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.