tuple可以最多將10個類型捆綁起來, 用法看代碼吧...
- #include <iostream>
- #include <string>
- #include <tuple>
- #include <stack>
- using namespace std;
-
-
- void Test2()
- {
- tr1::tuple <char, int, string, double> a('A', 1, "TEXT1", 123.321);
- cout << tr1::get<0>(a) << endl;
- cout << tr1::get<1>(a) << endl;
- cout << tr1::get<2>(a) << endl;
- cout << tr1::get<3>(a) << endl;
-
- stack <tr1::tuple <string, int> > s;
- for (int i=0; i<6; i++)
- {
- char buf[20];
- tr1::tuple <string, int> t(string("姓名")+itoa(i, buf, 10), i);
- s.push(t);
- }
- cout << "姓名/t學(xué)號" << endl;
- while (!s.empty())
- {
- tr1::tuple <string, int> t(s.top());
- s.pop();
- cout << tr1::get<0>(t) << "/t" << tr1::get<1>(t) << endl;
- }
- }
-
- void main()
- {
- try
- {
- Test2();
- }
- catch (exception e)
- {
- cout << e.what() << endl;
- }
- }
|