I have been having difficulty trying to figure out how to read in data backwards. I get the idea, but have no idea how to properly code it since it is string data from a txt file. I was given the basic file to start with, but need to add in an array that will not assume more than 100 records.
void main()
{
fstream custFile, custFileCopy;
string custRecord;
custFile.open("customer.txt", ios::in);
if(custFile.fail())
{ cout << "Master input file can't be opened. Program stopping." << endl;
return;
}
custFileCopy.open("custFileCopy.txt", ios::out);
if(custFileCopy.fail())
{ cout << "Input file can't be opened. Program stopping." << endl;
return;
}
getline(custFile, custRecord);
char c;
while (!custFile.fail() )
{ int i = 0;
while(!custRecord[i] == 0)
{ c = custRecord[i];
cout << c;
i++;
}
cout << endl;
custFileCopy << custRecord << endl;// write an output record
getline(custFile, custRecord); // read another input record
}
custFile.close();
custFileCopy.close();
}