Jump to content
  • Advertisement
Sign in to follow this  
Daaark

Character Array parsing tutorials?

This topic is 4970 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

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 this post


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


Link to post
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]

Share this post


Link to post
Share on other sites
Okay, I'm using a stringstream of the file, and getting one line at a time out of it into a char array, and it's working great so far. strtok is taking me a long way. :) I'm just stumped on one part... I need to grab 2 chars at a time out of a array into another... how can I do this?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!