STL 标准库 - 003

#include <iostream>
#include <string>//!!!
#include <tuple>
#include <functional>
#include <algorithm>

using namespace std;
std::tuple<int, string,string> fun(int i)
{
    string s1 = "param1";
    string s2 = "param2";
    std::tuple<int, string,string> t{ i,s1,s2 };
    return t;
}

int main()
{
    //构造tuple
    std::tuple<int, string> t1{ 1,"test" };
    cout<<std::get<0>(t1)<<" "<<std::get<1>(t1)<<endl;
    auto t2 = std::make_tuple(1,2,"str",1.2);
    cout<<std::get<0>(t2)<<" "<<std::get<1>(t2)<<endl;
    auto t3 = std::make_tuple(1,"2");
    //== !=
    if(t1 == t3){
        cout<<"=="<<endl;
    }else{
        cerr<<"!="<<endl;
    }
    //函数返回tuple
    auto t = fun(12);
    cout<<std::get<0>(t)<<" "<<std::get<1>(t)<<" "<<std::get<2>(t)<<endl;
    return 0;
}
©️2020 CSDN 皮肤主题: 大白 设计师: CSDN官方博客 返回首页
实付0元
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值