Allegro.cc - Online Community

Allegro.cc Forums » Game Design & Concepts » Arrays to files?

This thread is locked; no one can reply to it. rss feed Print
 1   2 
Arrays to files?
TeamTerradactyl
Member #7,733
September 2006
avatar

The basic ">>" operator stops at all whitespace, so it will read in "12345 4345 888" as three separate numbers (or strings of char, or even std::string's). It completely ignores whitespace (spaces and tabs), and newlines.

For a school project, we had been asked to read in a line of text, parse the important data, then continue to the next line, etc.

The "getline" function will stop at whitespaces (you can also tell it to stop at a certain character, like a space or even a specific character). If you have a stream (like an fstream), the parameters I've used are:
getline(fin, some_string, '\n'); to read in from "fin" input stream, save the data to the "some_string" string, and stop as soon as it sees a newline character. The third parameter is '\n' by default, so if you change it to something else, it will stop parsing "the line" when it hits that character (so if you have line-comments that start with '#', you can use that). If you leave off that third parameter, it assumes you want just to the end of the line.

Does that help?

 1   2 


Go to: