我想通過C++讀取一個巨大的txt。它有70MB。我的目標是逐行字符串並生成另一個更小的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) 未處理的異常:0000005:訪問衝突讀取位置0x3a70fcbc。
如果有人可以用C或C#指出解決方案,那也是可以接受的!
感謝=)
立即死亡嗎?中途加工?在處理文件結束時? –
您的輸入循環測試EOF的方式是[壞習慣](http://stackoverflow.com/questions/5605125/why-is-iostreameof-inside-a-loop-condition-considered-wrong)。 – Blastfurnace