简体   繁体   中英

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 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);

itoa函数将int转换为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会帮助你。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM