C++17 structured binding

使用C++17的结构化绑定可以根据一个函数的返回值同时定义多个变量,如下所示:

1
2
3
4
5
6
7
8
9
10
#include <iostream>
#include <tuple>
using namespace std;
int main ( ) {
tuple<string,int> student("Sriram", 10);
auto [name, age] = student;
cout << "\nName of the student is " << name << endl;
cout << "Age of the student is " << age << endl;
return 0;
}