문제

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
도움이 되었습니까?

해결책

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;

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top