Reputation: 33
I have written a C++ program I have multiple of CSV file used as input, which I open one at a time and close it after extracting data to a output file which is the only file.
I run getline(inFile,line); outFile << line << endl;
I run this code, only only few files it suddenly output after about 200-300 line after and have a big whitespace in my output CSV file
But when I slower the code, like system("Pause") in the loop, I can get extract what I want perfectly....
Is my program running to fast, why getline would be skipping part of what things I want?
I really have no idea where the problem is coming from, or where to start
Many Thanks!
if (dataname[i] == dataname)
{
inFile.seekg(datalength[i], ios::beg);
for (int j = 0; j < datacount[i]; j++)
{
getline(inFile, line);
outFile << line << endl;
}
}
Upvotes: 1
Views: 1280
Reputation: 921
Refer to Why seekg does not work with getline?
Add a clear() call before the seekg(pos) call to clear all error flags that might have been created by the getline(inFile, line) call.
inFile.clear(); // Clears all error flags.
inFile.seekg(pos);
Upvotes: 1