how to reuse stringstream

前端 未结 6 1152
遇见更好的自我
遇见更好的自我 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:40

    In most cases, it is easier to create a new istringstream or ostringstream instead of resetting the same ones.

    However, if you do want to resent them:

    • Resent flags of the stream (to avoid unexpected behavior) using clear ().

    • While you can correct the contents of your stringstream using str (""), for efficiency purposes we might prefer str(std::string()).

提交回复
热议问题