0
的我有以下的代碼:C++ - 不能移動istringstream定義出循環
#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'函數。另請參見:[在C++中,如何清除stringstream變量?](http://stackoverflow.com/questions/20731/in-c-how-do-you-clear-a-stringstream-variable) – jogojapan
您意思是http://en.cppreference.com/w/cpp/io/basic_istringstream/str? –
使用'iss.str(s);' – 0x499602D2