#include "Nathan_Ward_P-2.h"
#include <fstream>
usingnamespace std;
int main()
{
student general[6];
english eng_student[2];
history his_student[2];
math math_student[2];
string filename;
string lastname, firstname;
int numstudents;
cout << "Please enter the name of the file you wish to open:" << endl;
cin >> filename;
cout << "File name: " << filename << endl;
ifstream inFile;
inFile.open("test.txt");
if (!inFile)
cout << "Error: file not found." << endl;
else
{
cout << "Processing!" << endl;
inFile >> numstudents;
for (int counter = 0; counter < numstudents; counter++)
{
inFile.getline(lastname, 50, ',');
}
cout << "Here is the result:" << endl << endl;
}
return 0;
}
and my text file is:
Bunny, Bugs
math 90 86 80 95 100 99 96 93
Schmuckatelli, Joe
history 88 75 90
Dipwart, Marvin
english 95 76 72 88
Crack Corn, Jimmy
math 44 58 23 76 50 59 77 68
Kirk, James T.
english 40 100 68 88
Lewinsky, Monica
history 60 72 78
the compiler (xcode) give me the error: "No matching member function for call to 'getline'" on line 30. Any help would be appreciated :/
OK chervil that solved it! taking out the extra parameter for length it worked, as there is no longer an error message. However, when simply using cout to display lastname, it comes up blank.
Are you sure? i can certainly foresee problems because of the other data - the file doesn't contain only lastname, firstname. Have you output endl after each name? if not even though read in separately, they might appear all as one long line.
Yes the other data in the text file will be put to use once I can figure this problem out. the exact output is as follows:
Please enter the name of the file you wish to open:
test.txt
File name: test.txt
Processing!
Bugs
Bunny Joe math 90 86 80 95 100 99 96 93
Schmuckatelli Marvin history 88 75 90
Dipwart Jimmy english 95 76 72 88
Crack Corn James T. math 44 58 23 76 50 59 77 68
Kirk Monica english 40 100 68 88
LewinskyHere is the result:
Program ended with exit code: 0
It displays the whole text file, except it took out the commas
Well, if it displays the whole file, that's great! it means your code managed to keep on reading for all of the 6 students.
if you really want to get just this part working first, i suggest you use a modified input file, something like this:
6
Bunny, Bugs
Schmuckatelli, Joe
Dipwart, Marvin
Crack Corn, Jimmy
Kirk, James T.
Lewinsky, Monica
Alternatively add the code to at least ignore the intervening lines until you are ready to add the full details of the code. But really, it feels like I'm doing your job for you. i think you need to pause and think things through a little bit, I think you're heading in a reasonable direction so far.
HOLY CRAP I'M SO RETARDED. The for loop in line 28 has it going 6 times, and for my testing purposes it was constantly reassigning lastname and firstname to different parts of the file. Putting the loop from 0 to 1 in order to test it fixed the problem. OK everything is great and solved now. Thank you so much Chervil!