+ 3
How to store integer number 12345 in character array
3 odpowiedzi
+ 12
http://www.cplusplus.com/reference/cstdlib/itoa/
If your compiler doesn't support this, you can use the good ol' stringstream method.
#include <iostream>
#include <sstream>
int main()
{
std::stringstream obj;
std::string str;
int num = 12345;
obj << number;
// push number into string stream
obj >> str;
// push stream content to string variable
std::cout << str;
// now you have a string which can be used like a char array
}
+ 2
why to store a integer in character?
+ 2
And as a smaller way, In C++11 we have 'to_string()' for the same :
string no = to_string(12345);
cout<<no;
// We even have itoa() in C++ 11 for the string class...