#### Archived

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

# how can i convert int to char?

This topic is 5639 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 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 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 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

##### 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 on other sites
you can just do:

char buffer[16];
itoa(value, buffer, 10);

your result is a character string.

[edited by - TheJakub on July 5, 2003 4:08:24 PM]

##### Share on other sites
If you are using c++ and a modern compiler you could also use boost::lecical_cast. Look at www.boost.org

##### 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
______________________________________________________________

1. 1
2. 2
3. 3
Rutin
15
4. 4
5. 5

• 9
• 9
• 11
• 11
• 23
• ### Forum Statistics

• Total Topics
633679
• Total Posts
3013294
×