Search code examples
c++ifstream

C++ reading text file line by line stops partway through


I have a file with 16,900,000 lines, each line contains 10 numbers (mix of int and floats). I'm trying to read this file line by line, modify each line slightly, and write to a series of new files. The code below works on a laptop running Windows Visa, but when I run it on a desktop running Windows 7, the output file does not contain all the data from the input file. The number of lines in the output file varies from 2500 to 40,000.

I've commented out all of the processing, and writing to files, and just write every 100th line to cout, the last line to print isn't the last line of the file.

// skipping code prior to the loop
// only including minimal code that reproduces the problem
ifstream infile((srcdir+filename).c_str()); 
string line;
int lcount=0;

while(getline(infile,line)){
    if(line.find("#")==string::npos){
        lcount++;
        if(lcount%100==0){
            printf("Generating tiles for %s: %d lines processed\n",filename.c_str(),lcount);
        }

    }
}

Questions:

  1. Is there a maximum buffer size that I might be overflowing?

  2. Can anyone see a problem with my code?

  3. Is there any reason this would work fine on Windows Vista, but not on Windows 7?


Solution

  • While trying to create a minimal full program that would reproduce the problem, I found the culprit.

    I'm trying to secure the executable with the keylock dongle that my company is using. When I removed the check for the dongle, the entire file was read.