| | |
Inputting text file into array and finding top 3 values
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: May 2008
Posts: 5
Reputation:
Solved Threads: 0
Hey i've done what you've said but it stills seems to only read the one value and then the program never ends. do i need a getline sorta thing? or anything else
C++ Syntax (Toggle Plain Text)
bool readStudents(string fName, studentType stuList[], int& size) { ifstream inFile; studentType stu; size = 0; inFile.open (fName.c_str()); if (inFile.is_open()) { inFile >> stu.id >> stu.assignments[0] >> stu.assignments[1] >> stu.assignments[2] >> stu.exam; while(!inFile.eof()) { cout << stu.id << ", " << stu.assignments[0] << ", " << stu.assignments[1] << ", " << stu.assignments[2] << ", " << stu.exam << endl; cin >> stuList[size].id >> stuList[size].assignments[0] >> stuList[size].assignments[1] >> stuList[size].assignments[2] >> stuList[size].exam; cout << endl; size++; } return true; } else return false; inFile.close (); }
•
•
Join Date: Jan 2008
Posts: 3,844
Reputation:
Solved Threads: 503
•
•
•
•
Hey i've done what you've said but it stills seems to only read the one value and then the program never ends. do i need a getline sorta thing? or anything else
C++ Syntax (Toggle Plain Text)
bool readStudents(string fName, studentType stuList[], int& size) { ifstream inFile; studentType stu; size = 0; inFile.open (fName.c_str()); if (inFile.is_open()) { inFile >> stu.id >> stu.assignments[0] >> stu.assignments[1] >> stu.assignments[2] >> stu.exam; while(!inFile.eof()) { cout << stu.id << ", " << stu.assignments[0] << ", " << stu.assignments[1] << ", " << stu.assignments[2] << ", " << stu.exam << endl; cin >> stuList[size].id >> stuList[size].assignments[0] >> stuList[size].assignments[1] >> stuList[size].assignments[2] >> stuList[size].exam; cout << endl; size++; } return true; } else return false; inFile.close (); }
![]() |
Other Threads in the C++ Forum
- Previous Thread: problem with base class
- Next Thread: Editing and deleting data in a text file
Views: 847 | Replies: 11
| Thread Tools | Search this Thread |
Tag cloud for C++
6 api application array arrays based beginner binary c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete developer display dll dynamiccharacterarray email encryption error file format forms fstream function functions game generator givemetehcodez graph iamthwee ifstream image input int java lib list loop looping loops map math matrix memory multiple newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg search simple sort sorting spoonfeeding string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






