小编Foa*_*oal的帖子

如何连接字符串和整数来创建文件名?

我有一系列文件(New1.BMP,New2.BMP,...,New10.BMP).

我需要创建一个存储上述文件名称的变量,然后在另一个代码中使用它.

我目前的代码:

int LengthFiles =10;
char FilePrefix[100]="New";//This is actually passed to the function. Am changing it here for simplicity
char str[200],StrNumber[1];//str holds the file name in the end. StrNumber is used to convert number value to character
 SDL_Surface *DDBImage[9]; // This is a SDL (Simple DIrectMedia Library) declaration.
 for (int l=0;l<LengthFiles ;l++)
     {      
    itoa(l, StrNumber, 1);
    strcat(str,FilePrefix);strcat(str,StrNumber);strcat(str,".BMP");
    DDBImage[l]= SDL_DisplayFormat(SDL_LoadBMP(str));

     }
Run Code Online (Sandbox Code Playgroud)

正如您可能看到的,我不知道如何用C++编写代码,我试图通过在线代码片段来完成这项工作.这是它应该如何在C/C++中工作,即即时创建变量.

我该如何最好地接近它?

c++ sdl

2
推荐指数
1
解决办法
3611
查看次数

标签 统计

c++ ×1

sdl ×1