我想返回多个值并使用 声明该函数auto。
但这效果并不好。无法正确返回值。它被覆盖了。
我尝试执行以下功能f1〜f3。这些函数应该返回元组中的向量和字符串。但只是f3效果很好。
#include <iostream>
#include <vector>
#include <string>
#include <tuple>
auto f1(){
std::vector<double> v(10, 0);
std::string s = "hello";
return std::forward_as_tuple(v, s);
}
auto f2(){
std::vector<double> v(10, 0);
return std::forward_as_tuple(v, "hello");
}
std::tuple<std::vector<double>, std::string> f3(){
std::vector<double> v(10, 0);
std::string s = "hello";
return std::forward_as_tuple(v, s);
}
int main(void){
//change the function
//auto [vec, str] = f1();
//auto [vec, str] = f2();
auto [vec, str] = f2();
for (auto e : …Run Code Online (Sandbox Code Playgroud)