Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hi, How to convert double to st 1

Status
Not open for further replies.

MaheshRathi

Technical User
Jan 17, 2002
62
IN
Hi,

How to convert double to string? Appreciate, if you can give sample code in C++ on unix.

thanks,
Mahesh
 
It depends on whether your Unix compiler supports the new version of streams (#include <strstream>) or the old version of streams (#include <strstream.h>). This one is for the new version

string dtos (const double d)
{
ostringstream oss;
oss << d << ends;

return oss.str ();
}

If it is the old version, then you have to use char* instead of string and it gets messy as you must remember to delete the buffer once it has been accessed using .str ().
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top