vector< char>的优点过字符串? [英] Benefits of vector<char> over string?

查看:104
本文介绍了vector< char>的优点过字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此问题与此问题有关,但不完全相同。



使用 std :: vector< char> 而不是 std :: string 保持任意二进制数据,搁置与可读性相关的问题?



ie

解决方案

是的,

code>向下< char> c>
$ b

不能使用小缓冲区优化,但另一方面必须在<$ 期间保留迭代器,引用等c $ c> swap 操作。



请参阅: 可以 std :: vector 使用小缓冲区优化?


This question is related to, but not quite the same as, this question.

Are there any benefits to using std::vector<char> instead of std::string to hold arbitrary binary data, aside from readability-related issues?

i.e. Are there any tasks which are easier/more efficient/better to perform with a vector compared to a string?

解决方案

Yes, vector<char> indeed does have more capabilities over string.

It must not use the small buffer optimizations, but on the other hand it must preserve iterators, references, etc. during a swap operation.

See: May std::vector make use of small buffer optimization?

这篇关于vector&lt; char&gt;的优点过字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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