Archived

This topic is now archived and is closed to further replies.

Link

how can i convert int to char?

Recommended Posts

?? Futhermore i would know if using some function like atoi() it need link to some library also when i run the project it works good

Share this post


Link to post
Share on other sites
eh, what you want to do? convert an integer to a char string or just to a char?

If you want to convert your integer to a char string, then yes atoi is a good choice and no you don''t need to link any other libraries to use it.

If you want to convert your integer to a char, well then you''ll only be able to convert the integers from 0-9 and you can do that by: char myCharInt = 48+intToConvert;

Share this post


Link to post
Share on other sites
CAn''t you :

static_cast(int_to_turn_to_char)

???

Battleguard



Only questions raise questions. Questions are raised by people, by curiousity, the gift of nature to all human beings. And curiosity is satisfied by answers, which in turn raise questions, which lead to answers. And this curiosity is what keeps SCIENCE alive...

Share this post


Link to post
Share on other sites
quote:
Original post by angry
If you want to convert your integer to a char, well then you''ll only be able to convert the integers from 0-9 and you can do that by: char myCharInt = 48+intToConvert;


Dont use the_int + 48. Use the_int + ''0'' since it is not always true that the numbers begin at 48 while it is always true that they are sequential.



Qui fut tout, et qui ne fut rien
Invader''s Realm

Share this post


Link to post
Share on other sites
In which language, guess this is C as you point out atoi, or is this supposed to be a generic solution ?

atoi in c/c++ is fine, Int.ParseInt managed code...

Regards,
Steve

[edited by - steg on July 5, 2003 8:48:35 AM]

Share this post


Link to post
Share on other sites
C++

#include <sstream>
// blah, blah, blah...

std::ostringstream oss;
oss << some_integer;
char* ascii_form_of_int = oss.str().c_str();


______________________________________________________________
The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ
MySite
______________________________________________________________

Share this post


Link to post
Share on other sites