i want to parse a file,my problem is in lines 2,3,4 of each person(every 4line make a person from my class person)numbers of my variables in lines 2,3,4 changed.i want to push_back each of variable in line 2 in a vector until it comes to "\n",i want to continue this work(make person)until the cursor comes to "---------------" this is a sample of my text file:
I would use getline() to read in each line as a std::string. When it comes to those lines which are variable, read the string into a stringstream and use the >> extraction operator to pull out what you need.
That way you can compare each line with "----------" to see when to stop.
Is it reasonable for you to print file as binary file instead of text file? This way you can read and write entire structure. But yeah if you need a text file only then you can : Instead of ------------ you can use some character which you won't use anywhere.
read a line using getline and compare it with above symbol. If it is not true read thrice and each time separate strings. Then you can use atoi() and atof()
Take a substring (2 characters) of the string you read in using getline, and compare it to "--" (unless you think your professor will put in aberrant lines to test your program. Or if you know the number of dashes ahead of time, compare it with that.