c++ - 如何在字符串中插入一个整数?

标签 c++

如何将整数 i 插入到字符串中?我试过这个,但它不起作用:

for (int i = 0; i < maxFrameBoss1; i++) {
    boss1Image[i] = al_load_bitmap("boss1//frame_0" + i + "_delay-0.03s.png");
}

最佳答案

您需要先将i 转换为字符串。然后连接字符串。最后(显然)为您的 al_load_bitmap 获取指向 char 的指针:

for (int i = 0; i < maxFrameBoss1; i++) {
    std::string filename = "boss1//frame_0" + std::to_string(i) + "_delay-0.03s.png";
    boss1Image[i] = al_load_bitmap(filename.c_str());
}

关于c++ - 如何在字符串中插入一个整数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48449803/

相关文章:

c++ - NTRUEncrypt:无法使用开源标准算法中描述的正确找到两个多项式的 GCD,无法定义是否存在 poly 的倒数

c++ - 在给定数组中找到长度为 k 的所有连续子数组的总和

python - 如何在 C++ 中正确加载 python(3.0) 函数

c++ - 为什么我不能使用 std::thread 通过引用发送对象

C++:如何将 double 舍入为 int?

c++ - 指向函数指针数组的指针

C++ 无锁堆栈已损坏

C++ 通过引用返回堆栈分配细节

循环中指向int的C++指针?

c++ - 如何使用 C 或 C++ 从 dll 中读取导出表?