Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Laroche

fstream i/o with text

This topic is 5758 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Advertisement
Yes, fstream is a wrapper class for FILE* and the applicable functions.

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-

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!