读取二进制文件到一个bitset或矢量<&布尔GT; [英] Reading a Binary File into a bitset or vector<bool>

查看:140
本文介绍了读取二进制文件到一个bitset或矢量<&布尔GT;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何读取二进制文件到位集矢量<&布尔GT; ?二进制文件将在长度改变。是否有这更好的容器?我是新来的C ++虽然经历了作为一个程序员。

How do I read a binary file into a bitset or vector<bool>? The binary file will vary in length. Is there a better container for this? I am new to C++ though experienced as a programmer.

推荐答案

如果文件很大,你为什么要读一次,整个文件到内存?

If the file is large, Why should you read once, whole the file into the memory?

您可以阅读一小片每次。大小与确定的尺寸在这个FUNC 的:

You can read a little piece every time. The size is determined with the size in this func:

file.read(buff, size)

当的爱好者的为char的数组。

我很抱歉,但你不能简单的读/矢量保存到文件。
有关详细信息,看到这里和的这里

I'm sorry, but You can't simplest read/save vector to file. for more details see here and here.

和使用谷歌,这是非常有帮助...

And use Google, It's very helpful...

这篇关于读取二进制文件到一个bitset或矢量&lt;&布尔GT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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