Question

My code is working except for one problem, when I run it it doesn't seem to return the first string.

    string text;
    cin >> text;
    getline(cin ,text);
    istringstream  iss(text);
    copy(istream_iterator<string>(iss),
            istream_iterator<string>(),
            ostream_iterator<string>(cout, "\n"));

So if my input was, bf "ing" filename, it will only output:

"ing" 
filename

I want it so it can output the whole line like so:

bf 
"ing"
filename
Était-ce utile?

La solution

Assuming you want to have the entire line printed from parsing the string passed to std::istringstream you should remove first reading a separate word, i.e., remove the line

cin >> text;

Autres conseils

Get rid of

cin >> text; .

That one consumes the first word of your input, reads it into text, and then you discard it by overwriting text in the next line.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top