카테고리 없음
[Mastering C++ Programming] - Structured binding
sliver__
2022. 12. 3. 10:15
728x90
- 여러 개의 변수를 return value로 할당할 수 있다.
#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;
}
- -std=c++14 빌드 결과는 아래와 같다.
g++ MultipleVariable.cpp -std=c++14
MultipleVariable.cpp:8:10: warning: decomposition declarations are a C++17 extension [-Wc++17-extensions]
auto [name, age] = student;
^~~~~~~~~~~
1 warning generated.
- -std=c++17 빌드 결과는 warning / error 없이 빌드된다.
728x90