What's the difference between istringstream, ostringstream and stringstream? / Why not use stringstream in every case?

后端 未结 8 1765
春和景丽
春和景丽 2020-12-02 04:48

When would I use std::istringstream, std::ostringstream and std::stringstream and why shouldn\'t I just use std::stringstream

8条回答
  •  长情又很酷
    2020-12-02 05:13

    std::ostringstream::str() creates a copy of the stream's content, which doubles memory usage in some situations. You can use std::stringstream and its rdbuf() function instead to avoid this.

    More details here: how to write ostringstream directly to cout

提交回复
热议问题