stringstream to and from

Discussion in 'C++' started by Gary Wessle, Feb 14, 2007.

  1. Gary Wessle

    Gary Wessle Guest

    Hi

    is this done correctly? if not, how can it be done please?
    put what ever data in a stringstream then put that in a string
    and deal with it as a string.
    thaks

    stringstream oss; string f;
    oss << vec[8] << " "
    << var1 << " this is nice " << var_n << " " << endl;
    oss >> f;


    now if should be a long string contains all the pieces above?!

    thanks
     
    Gary Wessle, Feb 14, 2007
    #1
    1. Advertising

  2. Gary Wessle

    Ian Collins Guest

    Gary Wessle wrote:
    > Hi
    >
    > is this done correctly? if not, how can it be done please?
    > put what ever data in a stringstream then put that in a string
    > and deal with it as a string.
    > thaks
    >
    > stringstream oss; string f;
    > oss << vec[8] << " "
    > << var1 << " this is nice " << var_n << " " << endl;
    > oss >> f;
    >

    f will contain the first word output to oss. Try oss.str().

    --
    Ian Collins.
     
    Ian Collins, Feb 14, 2007
    #2
    1. Advertising

  3. Gary Wessle

    Gary Wessle Guest

    Ian Collins <> writes:

    > Gary Wessle wrote:
    > > Hi
    > >
    > > is this done correctly? if not, how can it be done please?
    > > put what ever data in a stringstream then put that in a string
    > > and deal with it as a string.
    > > thaks
    > >
    > > stringstream oss; string f;
    > > oss << vec[8] << " "
    > > << var1 << " this is nice " << var_n << " " << endl;
    > > oss >> f;
    > >

    > f will contain the first word output to oss. Try oss.str().
    >
    > --
    > Ian Collins.


    oss.str() >> f;
    error: no match for ¡Æoperator>>¡Ç in
    ¡Æstd::basic_stringstream<_CharT,
    _Traits, _Alloc>::str() const [with _CharT = char, _Traits =
    std::char_traits<char>, _Alloc = std::allocator<char>]() >> f¡Ç
     
    Gary Wessle, Feb 14, 2007
    #3
  4. Gary Wessle

    Ian Collins Guest

    Gary Wessle wrote:
    > Ian Collins <> writes:
    >
    >
    >>Gary Wessle wrote:
    >>
    >>>Hi
    >>>
    >>>is this done correctly? if not, how can it be done please?
    >>>put what ever data in a stringstream then put that in a string
    >>>and deal with it as a string.
    >>>thaks
    >>>
    >>> stringstream oss; string f;
    >>> oss << vec[8] << " "
    >>> << var1 << " this is nice " << var_n << " " << endl;
    >>> oss >> f;
    >>>

    >>
    >>f will contain the first word output to oss. Try oss.str().
    >>

    Please trim signatures.
    >
    > oss.str() >> f;
    > error: no match for ¡Æoperator>>¡Ç in
    > ¡Æstd::basic_stringstream<_CharT,
    > _Traits, _Alloc>::str() const [with _CharT = char, _Traits =
    > std::char_traits<char>, _Alloc = std::allocator<char>]() >> f¡Ç


    f = oss.str();

    --
    Ian Collins.
     
    Ian Collins, Feb 14, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. heiko
    Replies:
    0
    Views:
    1,051
    heiko
    Oct 1, 2005
  2. Mr Fish
    Replies:
    5
    Views:
    578
    Karl Heinz Buchegger
    Oct 21, 2005
  3. ma740988
    Replies:
    5
    Views:
    867
  4. Replies:
    2
    Views:
    473
    Rolf Magnus
    May 17, 2006
  5. FabioAng

    codecvt and stringstream

    FabioAng, Aug 8, 2006, in forum: C++
    Replies:
    1
    Views:
    504
    P.J. Plauger
    Aug 8, 2006
Loading...

Share This Page