Initialize a pair of vectors with a certain length and same numbers

124 Views Asked by At

What I want to achieve is to initialize a pair of a vector with a certain length and a certain initialization number

I know that a vector can be initialized with the same elements:

std::vector v(length, number); 

and a pair:

std::pair<int> p(number, number);

so combining those two together I thought of:

std::pair<std::vector<int>, std::vector<int>> pv((length, number),(length, number));

Unfortunately this doesn't work

2

There are 2 best solutions below

1
On BEST ANSWER
size_t length = 5;
int number = 0;
std::pair<std::vector<int>, std::vector<int>> pv(std::vector<int>(length, number), std::vector<int>(length, number));
1
On

You could use braces (list initialization) from C++11.

std::pair<std::vector<int>, std::vector<int>> pv({length, number}, {length, number});