Oh, by the way, what Joe has suggested here is a very bad
idea. The return value of std::string::c_str() is owned by the
std::string object and should not be modified, nor deleted etc..
If you do then you will find that you have a very unhappy
std::string on your hands.

December 8th, 2003, 03:42 AM

Kheun

Good point, souldog. That's because the memory of std::string is self-managed. If the memory of std::string is being directly manipulated, its state is most likely be corrupted.

By the way, I have find this similar thread which Andreas explained its usage.

December 8th, 2003, 03:44 AM

Graham

... and, of course, std::string::c_str() returns a const char *, so you can't pass it to sprintf, anyway.

December 8th, 2003, 03:57 AM

souldog

sprintf(const_cast<char*>(szStr.c_str()), "%.2f", dNum);

Oh the horror
:eek:

December 8th, 2003, 05:24 AM

Graham

souldog: please don't use language like that, there may children reading this. :p

December 9th, 2003, 07:39 AM

avi123

what is stringstream

I found it diffcult to find info about it?
what is it purpose

thanks

December 9th, 2003, 06:30 PM

Kheun

It is stream type that self-manages its memory. By using stringstream, you are equivalent to using sprintf-favour functions and manually managing your memory allocation and deallocation.

You can find information about STL from MSDN.

January 7th, 2004, 03:53 AM

avi123

Quote:

Originally posted by souldog
Hi, take a look at the following templates. I believe this
is covered in the FAQ as well