如何获取std :: stringstream的长度而不复制 [英] How to get length of std::stringstream without copying

查看:4442
本文介绍了如何获取std :: stringstream的长度而不复制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取字符串流的长度(以字节为单位)。

How can I get the length in bytes of a stringstream.

stringstream.str().length();

会将内容复制到std :: string。我不想制作副本。

would copy the contents into std::string. I don't want to make a copy.

或者如果任何人可以建议另一个在内存中工作的iostream,可以传递给另一个ostream写入,

Or if anyone can suggest another iostream that works in memory, can be passed off for writing to another ostream, and can get the size of it easily I'll use that.

推荐答案

假设你在谈论 ostringstream 它看起来像 tellp 可以做你想要的。

Assuming you're talking about an ostringstream it looks like tellp might do what you want.

这篇关于如何获取std :: stringstream的长度而不复制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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