How to create and initialize a vector of pairs to N times -1,-1 in C++

1 Answer

0 votes
#include <iostream>
#include <vector>

void print(const std::vector<std::pair<int, int>> vec) {
    for (int i = 0; i < vec.size(); i++) {
        std::cout << vec[i].first << ", " << vec[i].second << std::endl;
    }
}

int main()
{
    unsigned int N = 3;
    
    std::vector<std::pair<int, int>> vec = {N, std::make_pair(-1, -1)};
    
    print(vec);
}
  
  
  
  
/*
run:
  
-1, -1
-1, -1
-1, -1

*/

 



answered Jun 18, 2024 by avibootz
edited Jun 19, 2024 by avibootz

Related questions

1 answer 103 views
2 answers 175 views
1 answer 154 views
1 answer 121 views
1 answer 163 views
1 answer 279 views
...