如何在C ++中存储位数组? [英] How to store a bit-array in C++?

查看:70
本文介绍了如何在C ++中存储位数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C ++中存储位数组的最佳方法是什么(没有Boost,仅是标准容器),例如代表卷分配位图?

What's the best way to store a bit array in C++ (no Boost, just standard containers), representing, for example, a volume allocation bitmap?

我认为 std :: vector< bool> 是个好主意,但是

I thought std::vector<bool> was a great idea, but apparently it's Evil and deprecated, so is there a better choice?

如果我的内存中有一个字节数组,如何将它们复制到推荐的容器中?
(我很难为 vector< bool> 找出答案.)

If I have a byte array in memory, how would I go about copying them to the recommended container?
(I'm having trouble figuring this out for vector<bool>.)

推荐答案

仅在6年后发布以供后代使用:就像其中一位评论者所说,我得出的结论是,完全可以使用 std :: vector< bool> 作为其自己的专用类型.您唯一需要注意的是不要将其视为标准的 bool 容器,因为它不是.

Just posting this 6 years later for posterity: like one of the commenters said, I came to the conclusion that it's perfectly fine to use std::vector<bool> as its own specialized type. The only thing you need to be careful of is not to treat it like a standard bool container, since it isn't.

这篇关于如何在C ++中存储位数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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