C++ vector of pairs initialization

MyNameIsKhan picture MyNameIsKhan · Jun 19, 2012 · Viewed 48.8k times · Source

I have

vector< pair<int, int>> myVec (N);

I want to have all pairs initialized to -1,-1.

Answer

mfontanini picture mfontanini · Jun 19, 2012

Here you go:

#include <utility>

vector<pair<int, int>> myVec (N, std::make_pair(-1, -1));

The second argument to that constructor is the initial value that the N pairs will take.