+ 3

How to store integer number 12345 in character array

5th Sep 2017, 3:33 AM
Ajinkya Pawar
Ajinkya Pawar - avatar
3 Respostas
+ 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 }
5th Sep 2017, 5:29 AM
Hatsy Rei
Hatsy Rei - avatar
+ 2
why to store a integer in character?
5th Sep 2017, 4:13 AM
Cain Eviatar
Cain Eviatar - avatar
+ 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...
5th Sep 2017, 1:21 PM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar