我可以使用C ++代码在文件名中增加增量吗? [英] Can i put increment in filename with c++ code?

查看:63
本文介绍了我可以使用C ++代码在文件名中增加增量吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,
我必须在我的C ++程序中加载图像.图片的名称是数字,我的意思是像1.png 2.png等..
有没有办法使用循环将它们全部加载在一起
粗糙的代码:

Hello,
i have to load images in my c++ program. The name of the images is numeric , i mean like 1.png 2.png and so on..
is there any way to load all of them together using a loop
rough code :

for(int i = 0; i<10 ; i++)
loadfile (i".png") ;

instead of loading them one by one
loadfile("1.png");
loadfile("2.png"); 
.
.
.


我知道我写的是愚蠢的,但这就是我想做的:P

等待帮助.


i know what i wrote is stupid, but this is what i want to do :P

help awaited.

推荐答案

在您的循环中,尝试尝试以下操作:
In your loop, try something like:
std::ostringstream name;
name << i << ".png";
loadfile (name.str());


char szFileName[MAX_PATH];

for(int i = 0; i<10 ; i++)
{
    sprintf(szFileName, "Image%03d.png", i);
    loadfile(szFileName);
...


这篇关于我可以使用C ++代码在文件名中增加增量吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆