C++ - repeatedly using istringstream

前端 未结 2 1678
夕颜
夕颜 2020-11-29 08:43

I have a code for reading files with float numbers on line stored like this: \"3.34|2.3409|1.0001|...|1.1|\". I would like to read them using istringstream, but it doesn\'t

相关标签:
2条回答
  • 2020-11-29 08:59

    After setting the row into the istringstream...

    separate.str(row);
    

    ... reset it by calling

    separate.clear();
    

    This clears any iostate flags that are set in the previous iteration or by setting the string. http://www.cplusplus.com/reference/iostream/ios/clear/

    0 讨论(0)
  • 2020-11-29 09:03

    You need to add a separate.clear(); line after separate.str(row) to clear the status bits, otherwise the eofbit gets set and subsequent reads fail.

    0 讨论(0)
提交回复
热议问题