converting type double and int into strings

Hi everyone. I have a program that I used about six variables in. Five variables I used type double for and the other one I used type int. How do I convert their values into strings?

Thanks ahead of time for help
CI
Google works well. I found the answer in a few clicks.
I tried googling too. When I compiled though I would get some crazy errors telling me that what I am trying to do is illegal. I am using vs 2008. Thanks for the input.

-CI
Well, what code did you use?
@collinisaac0104
http://cplusplus.com/articles/numb_to_text/

@oghmaosiris
that depends on the googler
std::ostringstream strs;
strs << dbl;
std::string str = strs.str();


is their adifferent header file i need to include with this?
Last edited on
Can this work you think?

std::string str = boost::lexical_cast<std::string>(dbl);
what did you use?
int Number = ???;
string String = static_cast<ostringstream*>( &(ostringstream() << Number) )->str();

what if that number is stored in type int and we dont know exactly what it is. This would work right?
what do you mean "we dont know exactly what it is"?
within the prog, lets say double t * double r =double z and t is 3.12487894537 and r is 7894.23568, hypothetcially speaking. We dont know what z is unless we use cout<<z<<.
vs 2008 in windows form app doesnt allow cout. How can I generate what z is and put it on the windows form. I know how to put string type on the windows form app but not type int or double.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <windows.h>
#include <sstream>

template <typename T>
  std::string NumberToString ( T Number )
  {
     std::ostringstream ss;
     ss << Number;
     return ss.str();
  }

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
    LPSTR lpCmdLine, int nCmdShow)
{
    int number1 = 4564;
    double number2 = 545.354;
    MessageBox(NULL, NumberToString(number1).c_str(), "Integer", MB_OK);
    MessageBox(NULL, NumberToString(number2).c_str(), "Double", MB_OK);
    return 0;
}
Topic archived. No new replies allowed.