【发布时间】:2016-02-08 17:11:46
【问题描述】:
我正在尝试计算一个 const char *
这就是我将 int 转换为字符串并将其与 const char* 连接起来的方法
char tempTextResult[100];
const char * tempScore = std::to_string(6).c_str();
const char * tempText = "Score: ";
strcpy(tempTextResult, tempText);
strcat(tempTextResult, tempScore);
std::cout << tempTextResult;
打印时的结果是:Score:
有人知道为什么 6 不打印吗?
提前致谢。
【问题讨论】:
-
有什么理由不写
std::string textResult = std::string("Score: ") + std::to_string(6); std::cout << textResult << std::endl? -
@SimonKraemer 好吧,这与打印值无关。我需要它来渲染我使用 SDL 制作的游戏中的文本。