I have some 50 bytes lines in a text file containing something like this:
I want to pass it to a function to parse it. Looked like my best bet was stringstream. Here is my code:
0 111444550 sam fisher -1
Note: It goes int, 3 strings, long int. the first/last name are padded to 10 and 20 chars respectively (with blank spaces) and all vars are separated with one blank space.
somestruct = parseLine(buffer)
mystruct parseLine(stringstream rawline)
long int PTR;
return mystruct; //contains the 3 variables. edited function for clarity
What if I want to write to the file using a function?
Reading from it is easy since I just copy to a buffer and pass that. Writing using a function would require opening/closing a file stream which might need to be different than the one in int main().
What's the best way to handle it?
Any way to do it easily with pointers? without having to pass stuff back and forth?
Do I still use fstream without arguments to read and write?
Thanks for your time.