>) without removing it from the stream? Can I extract the string, check if" />
开发者

stringstream::operator>> only read, and not extract next token from stream

How can I just read the first new "token" (standard non-whitespace character sequence, as beautifully extracted by operator>>) without removing it from the stream? Can I extract the string, check if it needs to be put back, and reset the internal stream iterator? I think this might work, but have no idea how to implement it...

Example:

#include <string>
    using std::string;
#include <sstream>
    using std::stringstream;

int main()
{
    string s("test string \\ bla blie");
    stringstream ss(s);

    string token;
    while( ss >> token )
    {
        if( "\\" == token )
            break;
  开发者_如何学运维      else
            cout << "Token is: " << token << "\n";
    }
    return 0;
}

Would a tellg and seekg work here before and conditionally after the stream extraction?

Thanks!


Would a tellg and seekg work here before and conditionally after the stream extraction?

Yes.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜