0

次のコードがあります。

#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);ますが、この定義をループの外に移動することはできませんか?

(もちろん、それを移動すること可能ですが、私には何も達成できません。)

4

1 に答える 1

3

オブジェクト宣言の後にオブジェクト コンストラクターを呼び出すことはできません。さらにstd::istringstream::operator ()(std::string)、(通常) どこにも宣言されていません。

std::istringstream::str(…)構築後にコンテンツを割り当てるために使用します。

于 2013-06-12T08:08:20.020 に答える