Hey guys so i think all of my code is working except for reading my text file input. The text files will always be formatted with two names on a line, first and last name. And the next name will always come on the next line. I need to input a line, input the first word as the first name and the next as the last name. I've been trying but what i have just isn't working. Any thoughts? Thanks
Everything compiles and runs but during execution the array isn't even being filled from what i understand. I am definitely opening the file but my guess is there is an error somewhere in line 39-46 but i'm not sure what is going wrong, not very well versed in the stringstream stuff.
The text files will always be formatted with two names on a line, first and last name. And the next name will always come on the next line. I need to input a line, input the first word as the first name and the next as the last name.
Assuming that first and last names don't contain a white-space char, then the easiest way to read them is:
1 2 3 4 5 6
fstream MyReadFile(filename);
if (MyReadFile)
for (int x = 0; MyReadFile >> section1.student[x].firstName >> section1.student[x].lastname; ++x);
else
cout << "Problem opening file\n";
> getline(linestream, data, '\t');
you never mentioned a tab in the input, ¿why don't you show an example of your input file?
> the array isn't even being filled from what i understand
at each iteration of the loop
- ¿what does `line' contain? ¿is that correct?
- ¿what do `firstname' and `lastname' contain?
once the loop is finished, ¿what does the `section1.student' array contain? ¿how are you checking that?
if you didn't realise at this point, we can't see your screen