Thread: converting double to string??

  1. #1
    Waxy-Dock
    Join Date
    Mar 2005
    Posts
    69

    converting double to string??

    how do you convert from a double to a string in c++..

    i tried this...but i dont think its right (cause it doesnt work)

    NOTE:currentTime is the new string and time is the double

    /* convert double to string */
    std::strstream strm(currentTime,time,0);
    strm >> currentTime;

  2. #2
    Registered User Dante Shamest's Avatar
    Join Date
    Apr 2003
    Posts
    970
    I think <strstream> is deprecated. Use <sstream>.

    Code:
    string DoubleToString( double d )
    {
      stringstream ss;
      ss << d;
      return ss.str();
    }

  3. #3
    Registered User
    Join Date
    Dec 2004
    Posts
    95
    Or use boost

    Code:
    #include <boost/lexical_cast.hpp>
    
    double MyDouble = 1.602;
    std::string MyStr = boost::lexical_cast<string> (MyDouble);

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. functions and passing data
    By redmondtab in forum C Programming
    Replies: 41
    Last Post: 09-21-2006, 12:04 PM
  2. Help with multi function progam
    By WackoWolf in forum C Programming
    Replies: 22
    Last Post: 10-13-2005, 02:56 AM
  3. Program using classes - keeps crashing
    By webren in forum C++ Programming
    Replies: 4
    Last Post: 09-16-2005, 03:58 PM
  4. Something is wrong with this menu...
    By DarkViper in forum Windows Programming
    Replies: 2
    Last Post: 12-14-2002, 11:06 PM
  5. converting string to double
    By Unregistered in forum C++ Programming
    Replies: 8
    Last Post: 07-17-2002, 04:10 PM