2011-12-05 10 views

答えて

2

ファイルが大きい場合は、ファイル全体を一度メモリに読み込むのはなぜですか?

毎回小さな記事を読むことができます。 バフがcharの配列である場合には

file.read(buff, size) 

:サイズは、このFUNCでサイズで決定されます。

申し訳ありませんが、ファイルを読み込み/保存するのが簡単ではありません。詳細は see hereおよびhereです。

とGoogleを使用し、それはあなたがあなたの質問に何をしようとしてあまりにも多くの文脈を与えていない...

-1

非常に便利です。しかし、ここでそれを行うには1つの迅速&汚い方法です:

#include <iterator> 
#include <fstream> 
#include <vector> 
#include <assert.h> 
using namespace std; 

const char *filename = "foo.bar"; 
int main() 
{ 
    vector<bool> v; 
    ifstream binary_file(filename, ios::binary); 

    assert(binary_file); 
    copy(istream_iterator<unsigned char>(binary_file), 
     istream_iterator<unsigned char>(), 
     back_insert_iterator< vector<bool> >(v)); 
} 

ゼロバイトを読むには「\ 0」ベクターへの文字はfalseになります。読み込まれた他のバイトはすべて真と見なされます。

関連する問題