0

Is something like this is possible or there is any way to assign the pair values separately in for loop?

vector<pair<int, int>> arr;
// Input some values here in arr
for(auto &[x,y]: arr){
     cout<<x<<" "<<y;
}

1 Answers1

3

Your code is actually valid code in C++17 or later, as @MikeCAT said. You're using what's called a structured binding. It can unpack values from arrays or simple class types, in this case from pairs.

Anonymous1847
  • 2,568
  • 10
  • 16