O'Reilly logo

Mastering C++ Programming by Jeganathan Swaminathan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Structured binding

You can now initialize multiple variables with a return value with a really cool syntax, as shown in the following code sample:

#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;}

In the preceding program, the code highlighted in bold is the structured binding feature introduced in C++17. Interestingly, we have not declared the string name and int age variables. These are deduced automatically by the C++ compiler as string and int, which makes the C++ syntax just like any modern programming language, without losing its performance ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required