C++ 将 int 转换为字符数组?

标签 c++ arrays casting types char

<分区>

Possible Duplicate:
C++ convert int and string to char*

你好,我正在制作一个游戏,里面有一个计分板。分数存储在一个 int 变量中,但我用于游戏的库需要一个字符数组来为我的记分牌输出文本。

那么如何将 int 转换为 char 数组?

int score = 1234;  // this stores the current score

dbText( 100,100, need_the_score_here_but_has_to_be_a_char_array); 
// this function takes in X, Y cords and the text to output via a char array

我使用的库是 DarkGDK。

tyvm :)

最佳答案

ostringstream sout;
sout << score;
dbText(100,100, sout.str().c_str());

关于C++ 将 int 转换为字符数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3807635/

相关文章:

c++ - 基于 SonarQube 和 Qt 的资源

android - 带有 ubuntu 索引器的 C/C++ IDE

c++ - 回文在 C++ 函数中返回 false

java - 用逗号和空格分割输入的字符串

arrays - 快速将数组追加到数组

c++ - 尽管使用浮点运算,仍从 fmod 或类似的方法获得预期结果

java - 数组编程 - 检查井字游戏中有 n 个玩家的 nxn 棋盘的赢家

C# - 在指向同一内存位置的子类和父类之间使用等于运算符和方法

c - 这是什么(int**)&p;声明中的意思是?

c++ - reinterpret_cast 什么时候修改位?