I'm having issues using ofstream (Output stream class). I have a text file in my thumb drive called infile and I'm using ifstream to copy 7 integers ,but when I use ofstream to copy all 7 integers on each record I always get a duplicate line at the end. see code below. Another question I have is how do I do this with just one variable instead of using 7 numbers ?
I think the problem lies in the fact that once you have read the data values in the last line ... you aren't necessarily at the end of the file as CR and LF characters (I think) are still there. .eof is not a very reliable method here, though it may be better with getline than reading individual data.
Try preceding outFile on line 24 by
if (inFile)
which will be false once you have failed to read new data. Otherwise, you fail to read new data, so it simply duplicates the previous.
thank you it worked after adding if (inFile) at the end of the infile line like so
inFile >> num1 >> num2 >> num3 >> num4 >> num5 >> num6 >> num7; if (inFile)