最佳方式空stringstream? [英] Best way to empty stringstream?

查看:133
本文介绍了最佳方式空stringstream?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

其中一种可能性是:

somestringstream.str("");

但它是最优的吗?有什么办法保留stringstream内部缓冲区,以便下面的操作符<<()调用不需要再次保留内存。

But is it most optimal? Is there any way to preserve stringstream internal buffer, so that following operator<<() calls would not require to reserve memory again?

推荐答案

我一直在做:

s.clear();//clear any bits set
s.str(std::string());

@litb 进入更多细节关于如何seekp到流的开始与std :: ends结合你可以保留你分配的大小。

@litb gets into more detail about how to seekp to the start of the stream combined with std::ends you can keep your allocated size.

这篇关于最佳方式空stringstream?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆