Storing an integer into a char* in C++
I'm writing some code that returns an integer, which then needs to be outputted using printw from the ncurses开发者_如何学Go library. However, since printw only takes char*, I can't figure out how to output it.
Essentially, is there a way to store a integer into a char array, or output an integer using printw?
printw()
accepts const char *
as a format specifier. What you want is
printw("%d",yournumber);
The itoa function converts an int to char*.
Use itoa() or sprintf() to convert integer to ascii string.
Example:
char s[50];
sprintf(s, "%d", someInteger);
now u can pass s as char*
itoa will help you.
精彩评论