stringstream的大小 [英] Size of stringstream

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

问题描述

有什么直接的方法来计算stringstream中内部字符串的大小?

Is there any direct way to calculate size of internal string in stringstream?

这里, str()返回一个副本,然后它获取字符串的大小。

Here, str() returns a copy and then it gets the size of string.

std::stringstream oss("String");
oss.str().size();


推荐答案

std::stringstream oss("String");
oss.seekp(0, ios::end);
stringstream::pos_type offset = oss.tellp();

这是写指针,但是结果与Visual C ++ v10上的读指针一样。

This is for the write pointer, but the result is the same for read pointer on Visual C++ v10.

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

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