How to sort through a file

I have this file that I open up in this format

Number of Rooms:

treasure room
crystal lake
elm street

Doors leaving foyer:
Mountain 5.3
elm street 20.84

Doors leaving snakepit:
treasure room 1.2
crystal lake 3.84
foyer 7.902

Doors leaving treasure room:
crystal lake 7.93

Doors leaving mountain:
foyer 53.3
elm street 17.38
crystal lake 133.4

Doors leaving crystal lake:
foyer 17.348

Doors leaving elm street:
snakepit 1335.5
treasure room 5.6
crystal lake 17.89
mountain 4.2

and I want to take in this info but the formatting for my files will not change. They will always have this format with spaces in between all different fields, they will always have the title of the field followed by the : mark with the info on the next lines.

My question is how do I get the program to read in the input and skip the blank lines?
closed account (Dy7SLyTq)
while(getline(fileObject, stringObject))
Can you explain this a bit more. I'm somewhat new to this concept. Like I said, I need to make it skip blank lines and the title thing for the fields
fileObject is input istream or can be fstream as well.
stringObject is std::string;

read this:

also read about istream stream class.

so once you call getline, it will keep on giving you one line at a time in string object. you can do work with that string. you can put a check if the string is empty (it will be empty when a blank line comes) and can ignore that.

Topic archived. No new replies allowed.