【发布时间】:2013-06-12 08:05:52
【问题描述】:
我有以下代码:
#include <sstream>
#include <iostream>
using namespace std;
int main()
{
string inp, s;
istringstream iss;
do
{
getline (cin, inp);
iss(inp);
int a = 0, b = 0; float c = 0;
iss >> s >> a >> b >> c;
cout << s << " " << a << " " << b << " " << c << endl;
}
while (s != "exit");
}
会产生以下错误:
error: no match for call to ‘(std::istringstream) (std::string&)’
我知道可以通过在循环中使用istringstream iss(inp); 来避免该问题,但是是否不能将此定义移出循环?
(当然,是可以搬出去的,只是我什么都做不了。)
【问题讨论】:
-
我认为您正在寻找
istringstream的str函数。另请参阅:In C++, how do you clear a stringstream variable?
标签: c++ string istringstream