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) );

"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);

What if I am not constructing V1 (it already exists)?


and then...?

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 ) );
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.