I have an assignment where I need to extract data from a file using getline and write it to a new file. I got that to work, but now I can ONLY extract string variables using getline. I need to extract int and double variables from the file that come after the string but no matter what I put after getline, it gives me a random number whenever I try to extract and fout non-string variables.
What do I need to put after the last getline or fin.ignore so I can start reading int and double variables from the file again? I can't find anything in my textbook or on the forum about what to do once you're done with getline.
Okay so I kind of see what's going on in the second link with stringstream. So would I have to getline every int and double as a string first then convert it?
This is what my input file looks like:
Peter Griffin
101 Spooner St.
5125555555
123456789
25
3
88
80
96
86
88
25 and 3 are int, rest are double. I don't think I can tweak this too much without affecting my grade (otherwise I would have solved this hours ago by putting the int/doubles first and strings last and then just sorted them out as I wrote them to a new file) but I could probably get away with putting the same type of variables on one line. So my input would be:
Peter Griffin
101 Spooner St.
5125555555
123456789
25 3
88 80 96 86
So after my last getline I would put something like...?