【发布时间】:2013-11-27 23:02:48
【问题描述】:
我的代码是这样的:
double customer:: getAccounts()
{
for (int i=0;i<5;i++)
{
if(Accounts[i].getBalance() != 0)
{
double x = Accounts[i].getBalance();
return x;
}
}
}
目前您可以看到它只返回第一个帐户余额,然后在该返回点完成。但是我想以一种方法返回每个帐户余额以适应程序。这可能是一个字符串,但我不确定我会如何做到这一点。
我试过了:
string customer:: getAccounts()
{
string output;
std::ostringstream s;
for (int i=0;i<5;i++)
{
if(Accounts[i].getBalance() != 0)
{
double x = Accounts[i].getBalance();
s << x;
output += s.str;
}
}
return output;
}
但我得到以下信息:
错误 2 错误 C2679:二进制“+=”:未找到采用“重载函数”类型的右侧操作数的运算符(或没有可接受的转换)
还有:
错误 1 错误 C3867: 'std::basic_ostringstream<_elem>::str': 函数调用缺少参数列表;使用 '&std::basic_ostringstream<_elem>::str' 创建指向成员的指针
有人告诉我应该做什么吗? :s
【问题讨论】: