Sign in to follow this  
ssmith3

question about using istringstream

Recommended Posts

i am trying to parse a text file with the following format: integer:"string that might have spaces":"another string that might have spaces" is there a way that i can set the delimiters for the istringstream so it reads until it hits a : that is NOT in quotes?

Share this post


Link to post
Share on other sites
If you're feeling brave about Regular Expressions, you might be able to use boost::regex to achieve the task. Failing that, write a grammar using boost::spirit and use that to parse it.

As Fruny said, it's not the most trivial of tasks. You could write your own simple parser by reading the characters and using state machines if yu feel like a mini-challenge.

Share this post


Link to post
Share on other sites
thanks for the replys

i decided to end up using a regular expression library that i am pretty familiar with, just wanted to see if there was any easy way to use an istringstream with delimiters i set before i used the regex class

Share this post


Link to post
Share on other sites
Although you already have a solution, why not just take MSDN's advice on this topic:
Quote:

In such a case, one alternative is to use the unformatted input member function istream::getline to read a block of text with white space included, then parse the block with special functions. Another method is to derive an input stream class with a member function such as GetNextToken, which can call istream members to extract and format character data.

The parsing algorithm sure is simple. If you don't use Regex elsewhere it may be worth removing the dependency on it because of compilation speed and size concerns.

Thermo

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this