|
-
January 2nd, 2002, 03:46 PM
#1
ifstream problems with large files
I am writing an app to read from relatively large log files. Whenever I read from one that is 12MB in size I get an Unhandled Exception Error. If I use a the 2MB files that I have the program has no problem. From what it seems the problem is directly related to the STREAMB1.CPP file that the debugger is trying to load.
The call stack is as follows :
streambuf::stossc()
istream operator>>(char *)
Is there a max file size when using ifstream and the >> operator? The code I have reading the file is basically this
char finput[100];
CString input;
while (!inFile.eof())
{
inFile >> finput; // Dies on this line
input = finput;
// Do something with input
}
-
January 2nd, 2002, 04:05 PM
#2
Re: ifstream problems with large files
You're definining finput to be 100 in size.
if a line is longer than 99characters, it'll write outside of the buffer, corrupting memory, causing the crash.
-
January 2nd, 2002, 04:12 PM
#3
Re: ifstream problems with large files
But from what I understand >> reads the stuff in a word at a time. Let me try upping the read buffer to something a little large although I don't see any single word that is greater then 99 characters.
-
January 2nd, 2002, 04:17 PM
#4
Re: ifstream problems with large files
nah, it'll read stuff out of the file until a linefeed character is detected. it'll read the file a line at a time. Unless each word is on a separate line your assumption isn't correct :-)
-
January 2nd, 2002, 06:59 PM
#5
Re: ifstream problems with large files
Why don't you use STL functions and strings to read in the file line-by-line??
#include <string>
#include <iostream>
#include <fstream>
using std::cout;
using std::endl;
using std::string;
using std::ifstream;
int main()
{
string strLine;
// Open file
ifstream ifstrFile("c:\\test.txt");
if(ifstrFile.is_open() == false)
return -1; // Could not open file
// Read line-by-line
while(getline(ifstrFile, strLine))
cout << strLine << endl;
// Close file
ifstrFile.close();
return 0;
}
Ciao, Andreas
"Software is like sex, it's better when it's free." - Linus Torvalds
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|