What is the purpose of ostringstream's string constructor?

限于喜欢 提交于 2019-11-30 11:32:48

Using an ostringstream and providing an initial value is just like opening an existing file for writing. You have some data there, and unless you specify otherwise, your initial position will be at the beginning of the data. You can seek in the data, or you specify ios::ate to initially position the write pointer to the end of the existing data, or you can specify ios::app to always position the write pointer to the end of the existing data.

You can specify the second (optional) parameter of the constructor to set the stream cursor at the end:

std::ostringstream stream("initial string ", std::ios::ate);

To seek to the end, do this:

stream.seekp(0, ios_base::end);

As to why the write position defaults to the front, I don't know.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!