• Advertisement
Sign in to follow this  

Parsing Text file with ifstream..

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