私はC++で巨大なtxtを読み込もうとしています。それは70メガバイトを持っています。私の目的は、行ごとに部分文字列を作成し、必要な情報だけを含む別の小さなtxtを生成することです。C++から巨大なtxtファイルを読み込みますか?
私はファイルを読むために、以下のコードを手に入れました。小さなファイルでは完璧に動作しますが、70mbのモンスターでは動作しません。
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
ifstream myReadFile;
myReadFile.open("C:/Users/Lucas/Documents/apps/COTAHIST_A2010.txt");
char output[100];
if (myReadFile.is_open()) {
while (myReadFile.eof()!=1) {
myReadFile >> output;
cout<<output;
cout<<"\n";
}
}
system("PAUSE");
return 0;
}
これは私が取得エラーです:SeparadorDeAcoes.exeで0x50c819bc(msvcp100d.dll)で 未処理の例外:0xc0000005で:アクセス違反読み取り場所0x3a70fcbc。
誰かがCまたはC#で解決策を指摘できれば、それも受け入れられます!
感謝=)
すぐに死ぬのですか?途中まで?ファイルの処理の最後に? –
あなたの入力ループがEOFをテストする方法は[悪い習慣](http://stackoverflow.com/questions/5605125/why-is-iostreameof-inside-a-loop-condition-considered-wrong)です。 – Blastfurnace