How can we declare an oststream object in our own user defined class??
I tried this but it didn't work..
Code:class myclass { char str[80]; std::ostrstream(str,80); };
How can we declare an oststream object in our own user defined class??
I tried this but it didn't work..
Code:class myclass { char str[80]; std::ostrstream(str,80); };
Last edited by juice; 02-29-2012 at 06:32 AM.
Don't use ostrstream, use std::ostringstream.
Next, why do you want a stringstream as a member of the class?
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
The ostrstream class is deprecated. Is there any special reason why you want to use it?Originally Posted by juice
Yes. You should declare the object as a member:Originally Posted by juice
Then initialise it in a constructor. Note that you are not deriving from ostrstream.Code:class myclass { char str[80]; std::ostrstream; };
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
By using the constructor's initialiser list.Originally Posted by juice
No, because a class is a blueprint for objects of the class type.Originally Posted by juice
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)