PDA

View Full Version : How to convert int to char?



Bong.Da.City
22nd December 2010, 18:33
I have an integer and I want to convert it into char but keeping its value!! !!!

How to do that?

Lykurg
22nd December 2010, 18:42
Have a look here: http://lmgtfy.com/?q=int+to+char!

Bong.Da.City
22nd December 2010, 18:53
i google it but what i found didn't work... anyway delete the post because you do not want to answer

Lykurg
22nd December 2010, 19:02
anyway delete the post
Mine or yours?

squidge
22nd December 2010, 19:41
What you are asking for is impossible. Ints hold bigger numbers that chars, unless you are working on a system where the sizeof(int) is the same as sizeof(char).

What are you trying to do?

tbscope
22nd December 2010, 19:48
Most compilers accept the itoa(...) function

Lykurg
22nd December 2010, 19:51
Special trained in understanding questions, he wants:
char *c;
int i = 12345;
// here do the magic here with i and c.
cout << c; // this should print: 12345.But as told: google is nice to you if you ask it or simply grab the documentation for Qt and start with the QString documentation.

SixDegrees
22nd December 2010, 20:44
In addition to the above, C++ stringstreams solve this problem nicely.

Assuming the problem has been interpreted correctly. It's really impossible to decipher the original post.

wysota
23rd December 2010, 09:57
In addition to the above, C++ stringstreams solve this problem nicely.
And so does QTextStream.

Goddard
8th January 2015, 22:47
It is always funny how on forums people tell you to Google something. When in fact Google returns this as the first result and usually results for other things.

d_stranz
9th January 2015, 00:43
Ah, but you see this is an example of metahistory. At the time of the original post, this post didn't exist in Google's list of results. So if you click on the lmgtfy link in Lykurg's first reply, you pass through a wormhole and emerge into an alternative universe where the future is known in the past, because now this post appears in the list of search results.

wysota
9th January 2015, 06:28
Actually the link in Lykurg's post does not return this thread to me :) It does return a lot of results telling how to convert an int to a C string, though.

jefftee
9th January 2015, 19:45
I have an integer and I want to convert it into char but keeping its value!! !!!

How to do that?
Unless I am misunderstanding what you want, I would suggest you look at QString::number.