我必须编写一个代码,它具有一个函数,它带有两个整数,并返回x(a + b)和y(a * b),当我运行它时,它仅输出y。为什么不输出(或返回)x?从1函数返回并输出2个整数
#include <iostream>
using namespace std;
int math (int a, int b) {
int x, y;
x = a + b;
y = a * b;
return x, y;
}
int main() {
cout << math (5,3);
getchar();
getchar();
return 0;
}
你可能还会提到['std :: tie()'](http://en.cppreference.com/w/cpp/utility/tuple/tie) – 2014-11-09 00:19:44
@BillLynch'std :: tie'如何帮助这里? – 2014-11-09 00:38:42
你不是真的想暗示他使用'std :: pair',对吧?你真的认为'first'和'second'是这些字段的合适名称吗? (实际上,如果需要维护代码,使用'std :: pair'几乎不是一个好的解决方案。) – 2014-11-09 00:40:13