[C++] What’s an efficient way to split a vector into multiple smaller vectors? via /r/learnprogramming


[C++] What’s an efficient way to split a vector into multiple smaller vectors?

Let's suppose that I have the following, vector<int> X = {1,2,3, … , 1000};

I would like to create smaller x vectors that only contain the first 4 digits of the main vector X.

vector<int> x1 = {1,2,3,4}; vector<int> x2 = {5,6,7,8}; and so on. 

I've found a way to split a vector in to smaller ones but I'm completely stuck on how I can automate this. The command which I'm using to split is the following.

vector<int> x1(X.begin(), X.begin() + 4); 

Thanks. 🙂

Submitted July 12, 2017 at 08:35AM by VonLuftwaffle
via reddit http://ift.tt/2sPUC5K

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s