How do you clear a stringstream variable?

后端 未结 8 2032
时光说笑
时光说笑 2020-11-22 13:53

I\'ve tried several things already,

std::stringstream m;
m.empty();
m.clear();

both of which don\'t work.

8条回答
  •  天涯浪人
    2020-11-22 14:13

    You can clear the error state and empty the stringstream all in one line

    std::stringstream().swap(m); // swap m with a default constructed stringstream
    

    This effectively resets m to a default constructed state

提交回复
热议问题