|
|
发表于 2016-1-3 01:24:10
|
显示全部楼层
#include "stdafx.h"
#include <tuple>
#include <string>
#include <iostream>
using namespace std;
auto foo()
{
return make_tuple(39,string("str"));
}
struct MyStruct
{
int num;
string str;
}foo2() { return MyStruct{ 40, "strr" }; };
auto foo3()
{
return make_pair(41, "strrr");
}
int main()
{
cout << "foo" << endl;
auto bar = foo();
cout << get<0>(bar) << endl;
string str;
tie(ignore, str) = bar;
cout << str << endl;
cout << endl << "foo2" << endl;
auto bar2 = foo2();
cout << bar2.num << endl << bar2.str << endl;
cout << endl << "foo3" << endl;
auto bar3 = foo3();
cout << bar3.first << endl << bar3.second << endl;
return 0;
}
|
|