I made this program to read the id, grade and name of a student and to create a file with this information and than to open that same file and display the info on the file created, but my problem is this, i for example put in:
Grade Id Name
50 1 Tim
75 2 John
It writes the above to the file but when it displays on the screen it shows the second line twice like such
Grade Id Name
75 2 John
75 2 John
Here is what i wrote
I cant figure out whats wrong,Code:#include<iostream> #include<fstream> #include<string> #include<iomanip> using namespace std; int main() { int id, b; double grade; string filename, name; ifstream III; ofstream OOO; cout << "Please enter name for the output file" << endl; cin >> filename; OOO.open(filename.c_str()); OOO << setw(10) << "Grade" << setw(10) << "Id" << setw(10) << "Name" << endl; cout << "Enter number os students that you are going to input information" << endl; cin >> b; for (int f=1; f<=b; f++) { cout << "Enter grade, id and name for student number " << f << endl; cin >> grade >> id >> name; OOO << setw(10) << grade << setw(10) << id << setw(10) << name << endl; } OOO.close(); III.open(filename.c_str()); cout << setw(10) << "Grade" << setw(10) << "Id" << setw(10) << "Name" << "\n"; for (int f=1; f<=b; f++) { III >> grade >> id >> name; cout << setw(10) << grade << setw(10) << id << setw(10) << name << "\n" ; } III.close(); system ("pause"); return 0; }
Thanks in advance



LinkBack URL
About LinkBacks



