Parsing a file with different rows.

I have to parse a text file and each row is completely different from the previous one. I know how to parse a file when each row has the same format but I have no idea how to do it this way. My file has this format.

String Float
String Int
String float float float
String float float float
float
string
float float float
int.

Any help? I really have no idea where to start.

Thank you.
What are you supposed to do with it after you parse it? If your goal is just to parse and do nothing else...it doesn't make sense.
I have to store the values and use them later.
I guess my question is ho to read line by line and store each line differently.
so different line uses different input

why not use getline?
it takes string per line

if you need to divide them into array of words,
then divide them up later on,,,

if there is a pattern for this seemly random input then you can use something more efficient, well that all depends on how will you use the input ...

No, there is no pattern.

So I would get the lines using:

while (!file.eof())
getline(file, line);

but then every line would get stores in the variable line, so at the end of the loop I would just end up with the last line right? How do I store each line separately?


Thanks for the replies !
You could push the line to the back of a vector of strings ;)
okay ! and is there a way to do it without using vectors? Like just variables? I feel it would be easier to use them later like that
The easiest way to do it is using std::vector. Alternatives are more challenging and easier to get wrong. Also, std::vector is "just variables".
Last edited on
Okay, I am going to try your way.

Thanks :)
Topic archived. No new replies allowed.