Search code examples
c++vectorstd-pair

C++ vector of pairs initialization


I have

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

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


Solution

  • 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.