stringstream

I have a question about stringstream.

I understand it is the now standardized form of strstream.
Seems like I should not use strstream anymore.

When I declared a stringstream using VC++ 6.0, I get the following error:


stringstream sstr;


timestamp.cpp(52) : error C2079: 'sstream' uses undefined class 'basic_stringstream,class std::allocator >'


From what I know, a stringstream is typddef'd to be a basic_stringstream.

What's going on?
--------
Along the same lines (and the reason I'm trying to declare a stringstream in the first place):

I need to convert a long int into a std::string. I don't want to convert it using a non-ANSI ltoa and THEN convert to a string. I want a good, solid, Standard C++ way.

Why doesn't the std::string class overload op= to take atomic datatypes?

Thanks,

Matthew.

Comments

  • : When I declared a stringstream using VC++ 6.0, I get the following error:
    :
    :
    : stringstream sstr;
    :
    :
    : timestamp.cpp(52) : error C2079: 'sstream' uses undefined class 'basic_stringstream,class std::allocator >'
    :
    :
    : From what I know, a stringstream is typddef'd to be a basic_stringstream.
    :
    : What's going on?

    #include

    Cheers,
    Eric



  • : : When I declared a stringstream using VC++ 6.0, I get the following error:
    : :
    : :
    : : stringstream sstr;
    : :
    : :
    : : timestamp.cpp(52) : error C2079: 'sstream' uses undefined class 'basic_stringstream,class std::allocator >'
    : :
    : :
    : : From what I know, a stringstream is typddef'd to be a basic_stringstream.
    : :
    : : What's going on?
    :
    : #include
    :
    : Cheers,
    : Eric
    :
    :
    :

    Eric,

    your the man. That's twice.

    Do you know why they don't allow direct int or double assignment to a string??

  • : Do you know why they don't allow direct int or double assignment to a string??

    I would just causes too many headaches. It's like implicit conversion: it defeats the type system, so the compiler can no longer catch mistakes for you. In other words, if you have some object will accept assignments of any other type and happily convert it into [italic]something[/italic], how can the compiler catch catch the times where the assignment was accidental? You can't.

    For similar reasons stringstring and string classes do not provide 'operator char*' or 'operator const char*'; they would just cause more trouble that they are worth.

    Besides, stringstream (like all other streams) overloads << for all the builtin types, so you can just say:

    [code]mystring << 34 << 3.14;[/code]

    Cheers,
    Eric


  • You should include the following header file:
    #include
  • You should include the following header file:
    #include
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion