Re: c++ string stuff

From: MrPlow (desolate19_at_hotmail.com)
Date: 02/24/04


Date: Tue, 24 Feb 2004 03:42:01 GMT

Chris ( Val ) wrote:
<snip>
>
> There are ways :-).
>
> # include <iostream>
> # include <fstream>
> # include <ostream>
> # include <string>
>
> int main()
> {
> std::ifstream fuser( "Test.txt" );
>
> std::string fline;
> std::string::size_type Pos( 0 );
>
> while( std::getline( fuser, fline ) && fuser >> std::ws )
> if( ( Pos = fline.find_first_of( ':' ) ) != std::string::npos )
> std::cout << fline.substr( 0, Pos ) << std::endl;
>
> return 0;
> }
>
> Cheers.
> Chris Val
>
>

Thanks everyone for the helpful replies. This example comes the closest
to what I was wanting :) I think my problem was that in trying to get
rid of C strings, I was throwing out all techniques for working with
strings too and thinking that I should do everything with iostream type
stuff. I'll only have to change this slightly since I can't assume that
there won't be a ':' in a comment line.

Thanks again



Relevant Pages

  • Re: Boost process and C
    ... snip ... ... of int for sizes, rather than size_t. ... read-only and constant strings and detecting errors efficiently ... because at worst its giving up things (super-long strings) that nobody ...
    (comp.lang.c)
  • Re: Boost process and C
    ... snip ... ... of int for sizes, rather than size_t. ... read-only and constant strings and detecting errors efficiently ... Handling an RTF document that you will be writing to a variable length record in a database. ...
    (comp.lang.c)
  • Re: Boost process and C
    ... snip ... ... of int for sizes, rather than size_t. ... read-only and constant strings and detecting errors efficiently ... Silly encoding tricks buy you nothing, just use another field with bit ...
    (comp.lang.c)
  • Re: Boost process and C
    ... snip ... ... of int for sizes, rather than size_t. ... read-only and constant strings and detecting errors efficiently ... If I do that, I lose space, speed, and error detection. ...
    (comp.lang.c)
  • Re: Boost process and C
    ... of int for sizes, rather than size_t. ... read-only and constant strings and detecting errors efficiently ... where Bstrlib fails to be able to deal with them due to its design ... If the DOS port hadn't been dropped then depending on the compiler we ...
    (comp.lang.c)