• 12
• 27
• 9
• 20
• 33

# Character Array parsing tutorials?

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

## Recommended Posts

Anyone know any good character array parsing tutorials? I'm trying to load files into char buffers so I can parse them, but I have no idea how to go about it. I'm not looking for a listing of string functions, but some examples of putting them all together. (I'm using C++/MinGW)

##### Share on other sites
In C++ you can load a file into an std::string (one of C++'s native string types) in a few lines of code.

#include<sstream>#include<fstream>#include<string>int main(){std::stringstream ss;std::ifstream file("myfile.txt");ss << file.rdbuf();std::string filecontents = ss.str();}

The contents of the file are then in the filecontents string.

You could then use something like boost::tokenizer to parse the string.

##### Share on other sites
What's the diff between a stringstream and a string?

##### Share on other sites
Okay, I know the difference now. :) I was writing a parser using just fstream, but everything starts to go to hell at some point, and I can never find out why. I will do an fstream.get and it will return 0 when it should be returning say '3' and I know exactly where in the file I am. :| I ave rewritten my file parser 3 times because of this...

[Edited by - Vampyre_Dark on March 9, 2005 12:56:16 AM]