Jump to content
  • Advertisement
Sign in to follow this  
jamesss

Parsing Text file with ifstream..

This topic is 3909 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 want to read settings.txt like below...how should i parse [Sections] and key-value pairs via C++ I/O ? i just need to know how to parse.thanks [SYSTEM] ScreenWidth = 1024 ScreenHeight = 768 Windowed = 1

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by jamesss
i want to read settings.txt like below...how should i parse [Sections]
and key-value pairs via C++ I/O ? i just need to know how to parse.thanks

[SYSTEM]
ScreenWidth = 1024
ScreenHeight = 768
Windowed = 1
Take a look at:

std::map
std::string
std::getline()
boost::split()
boost::lexical_cast()

Using these tools (or just the SC++L stuff if you prefer), you can parse the file and read the key-value pairs into a map, which you can then query by key to get the corresponding value (which, in turn, you can then lexically cast to the appropriate type).

Share this post


Link to post
Share on other sites
Actually for a sizable project it might be worth wile to use lua to load in your configurations. Its small and very ez to use. take a look at: this

And if you are gonna get into any scripting for AI you will already have a foundation with a very useful scripting language.

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!