string stream usage
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: string stream usage

Hybrid View

  1. #1
    Join Date
    Mar 2010
    Location
    Melbourne Australia
    Posts
    454

    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 .

  2. #2
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,202

    Re: string stream usage

    So... what's stopping you from performing the checks?
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  3. #3
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    3,654

    Re: string stream usage

    You may want to have a look at the <regex> classes in the standard library, those would be the ideal candadates to do the kind of pattern matching that you seek

  4. #4
    Join Date
    Mar 2010
    Location
    Melbourne Australia
    Posts
    454

    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.

  5. #5
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,202

    Re: string stream usage

    Quote Originally Posted by aamir121a
    it is not pattern matching , more data validation
    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.

    Quote 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.
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center