i have a sequential access file named number.txt which contains the numbers 10 thru 20 I'm trying to write a program that reads the number.text file and add a value of one to each number and then write it's to a sequential file called updatedNunber.txt. I'm so confused I'm about to take up heavy drinking.if anyone one could help me clean up my program i appreciate a lot a whole lot.
//determine whether the file was opened
if (inFile.is_open())
{
//read a record
getline(inFile, name);
inFile >> num;
while (inFile.eof())
{
//display the record
cout << name << " " << endl;
//read another record
getline(inFile, name);
inFile >> num;
}
inFile.close();
}
else
cout << "The file could not be opened." << endl;
//create file object and open the file
ofstream outFile;
outFile.open("updatedNumbers.txt", ios::out);
//write the updated numbers to the file
outFile << heading << endl << endl;
outFile << columnHeaders << endl;
outFile << underLines << endl;
for (int x = 0;x += 1)
outFile << num[x] << endl;
//end for
outFile << endl << ;
In your for loop
for (int x = 0;x += 1)
write it like this
for(int x = 0; x++)
If you don't know the reason, x++ is NOT the same as x += 1. At least on the inside they aren't...In a benchmark it's also shown that using the increment value is faster than the ladder. Though this link doesn't prove it, it shows other things.
http://www-numi.fnal.gov/offline_software/srt_public_context/WebDocs/Companion/cxx_crib/increment.html