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;
}
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;
}
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 pair
s.