C++返回多个值

#include <tuple>
#include <iostream>

std::tuple<int, double, long long, char> test(int a)
{
    return std::make_tuple(a, a*3.5, a*a, a%10 + 'a');
}
int main()
{
    int a;
    double b;
    char c;
    std::tie(a, b, std::ignore, c) = test(3);
    auto r = test(5);
    std::cout << std::get<0>(r) << std::get<2>(r) << std::endl;
    return 0;
}

 

Add a Comment

电子邮件地址不会被公开。 必填项已用*标注

20 + 6 =