If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

string stream usage

I am working on a project were I have to read line form ( PLC ) programmable logic controller generated text file with lines like this

Circuit Value Current 2.33 4.32 5.55
there could be up to 3000 lines per txt file

I am using string stream to parse the line , for the sake of good programming I which to check weather first three values are string and last three values are actually floats
raise or throw an exception if they are not , any help in this regard would be much appreciated .

Re: string stream usage

it is not pattern matching , more data validation , thank you for your post , I actually did this with boost::lexical_cast , throws an exception if the required value is neither float or a string.
depends on how you set it up.

Re: string stream usage

Often input data validation involves some kind of pattern matching, so OReubens' suggestion is still relevant, though it may or may not be ideal for your case.

Originally Posted by aamir121a

I actually did this with boost::lexical_cast , throws an exception if the required value is neither float or a string.

Internally, boost::lexical_cast uses stringstreams. The basic idea here is to just parse with the stringstream, then check the state of the stringstream. If it is in a good state, or if you have reached the end and it is in EOF but not fail state, then the input can be considered valid.

* The Perfect Platform for Game Developers: Android
Developing rich, high performance Android games from the ground up is a daunting task. Intel has provided Android developers with a number of tools that can be leveraged by Android game developers.

* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.