简体   繁体   中英

How to make multiple vectors in c++

Brief :-

How to make multiple vectors ?
We generally make vectors using - vector<int> vector_name;
But any method to make multiple vectors at once ?

I assume that you're trying to create multiple vector at once and store them . You can use a simple for loop, or use a vector of vectors! For example:

#include <vector>

// Using a for loop
//#define VECTOR_COUNT 5 (EDIT)
constexpr int VECTOR_COUNT = 5;
std::vector<int> myFiveVectors[VECTOR_COUNT];
for(int i = 0; i < VECTOR_COUNT; i++)
    myFiveVectors[i] = {1, 2, 3};

// Using vector of vectors
std::vector<std::vector<int>> myVectors{};
myVectors.push_back({1, 2, 3});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM