fstream i/o with text
I''m not quite sure how I would use fstream to read in a text file, or portions of it. I''ve managed to be able to save a map file in my own format (a text format), and now i want to be able to read it back in, while scanning for certain things. for example, i want to be able to write functions like GetNextWord(), and stuff like that. How would I do this? Does it work the same way as a FILE *p?
Yes, fstream is a wrapper class for FILE* and the applicable functions.
Here''s something that should work off the top of my head:
-G|aD-
Here''s something that should work off the top of my head:
string getNextWord(ifstream& inputFile) { char wordBuffer[100]; inputFile.getline(wordBuffer, 100, '' ''); return string(wordBuffer); }
-G|aD-
Hmm, that sort of works, but i need JUST the next word, not exactly 100 characters length. The function picks up 100 characters, even if they are not part of a word. A word would be defined as a character all the way until the terminating character (a space, or a }, in my case). How do i check the character the file* is currently on?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement