Learning c++ -- reading numbers from a file -


quick synopsis: can write data file correctly (i've checked .txt file , presents should) can read last number inputted. so, if last quiz grade input 85, that's read back. (the studentnumber reads fine.) all! still learning here ...

while (answer == 1) {    cout << "what student id?\n";    cin >> studentnumber;    cout << "\n";    cout << "how many quizzes did take?\n";    cin >> numquiz;    outputfile << "\n";    outputfile << studentnumber << "\n";    outputfile << "number of quizzes: " << numquiz << "\t" "grades: ";    (int quiz = 1; quiz <= numquiz; quiz++)     {         cout << "please enter score quiz " << quiz << "\t";       cin >> score;       total += score;       // cout << "the score " << score << " .\n";        outputfile <<  score << "\t"; }     // outputfile <<  total;     cout << "do have student's grades input?\nif yes, type 1. if no, type 0.\n";    cin >> answer;    cin.ignore();   }  outputfile.close();  fstream inputfile;    inputfile.open("grades2.txt"); inputfile >> studentnumber; cout << studentnumber << "\n";  inputfile >> score; cout << score << "\n"; 

you using wrong operator read data back. instead of

inputfile << studentnumber; 

you need use

inputfile >> studentnumber; 

Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -