how to reuse stringstream

前端 未结 6 1148
遇见更好的自我
遇见更好的自我 2021-01-03 22:12

These threads do NOT answer me:

resetting a stringstream

How do you clear a stringstream variable?

        std::ifstream file( szFIleName_p )         


        
6条回答
  •  别那么骄傲
    2021-01-03 22:34

    You didn't clear() the stream after calling str(""). Take another look at this answer, it also explains why you should reset using str(std::string()). And in your case, you could also reset the contents using only str(szLine).

    If you don't call clear(), the flags of the stream (like eof) wont be reset, resulting in surprising behaviour ;)

提交回复
热议问题