I'm attempting to write two methods. One, ReadData(istream&) to read in student's ID number, first and last names, 10 program scores, and midterm and exam scores(last two integers) and returns true if all data was read successfully, false otherwise, and one, WriteData(ostream&) to write the data that was read in to a new file in the same order listed above.
I am completely new to file reading and writing so any and all help is much appreciated. The data I am using looks like this...(made up names and scores)
10601 ANDRES HYUN 88 91 94 94 89 84 94 84 89 87 89 91
10611 THU ZECHER 83 79 89 87 88 88 86 81 84 80 89 81
10622 BEVERLEE WAMPOLE 95 92 91 96 99 97 99 89 94 96 90 97
10630 TRUMAN SOVIE 68 73 77 76 72 71 72 77 67 68 72 75
So far I have...
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
ifstream ReadData;
ReadData.open("filename.txt");
if ReadData... ///Not sure how to make it return true or false
ReadData.close();
ostream WriteData;
for (k=0,k<101,k++)
//how do you output to a new file from here?
WriteData.close();
Use these for better control (handle could be ReadData or WriteData e.t.c):
Possible way to output data:
Another:
If the data is in a string you can just do:
There is a great tutorial here on c++ and files.
For file reading:
Output: just like
cout
: Like input, you must.open(..)
a new file before you can write in it