Click here to Skip to main content
16,012,611 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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 :

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

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

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

help awaited.
Posted
Updated 21-Dec-11 9:00am
v2
Comments
Wendelius 21-Dec-11 15:00pm    
Pre tags added
Albert Holguin 21-Dec-11 15:19pm    
As you can see from solutions... in general terms... turn the name into a string and use the string as the file name loaded into your function, and there's a variety of ways of doing so.

C++
char szFileName[MAX_PATH];

for(int i = 0; i<10 ; i++)
{
    sprintf(szFileName, "Image%03d.png", i);
    loadfile(szFileName);
...
 
Share this answer
 
Comments
Ghost_x 22-Dec-11 12:25pm    
i tried but its not working for me :/
what exactly i want to do is load 10 image handles into an array
ImageAdd("Assets/1.png");
ImageAdd("Assets/2.png");
so on to 10
now how can i load them using an array instead of typing all the statements one by one ..
JackDingler 22-Dec-11 12:52pm    
What is not working?

What errors are you getting?
JackDingler 22-Dec-11 12:53pm    
Are you stepping through the code with the debugger?
JackDingler 22-Dec-11 13:03pm    
Do you see how my file name is subtly different than yours?

Can you determine what you need to change to adapt my example to your needs?
Ghost_x 24-Dec-11 2:27am    
Thanks, i got it figured out :)
In your loop, try something like:
C++
std::ostringstream name;
name << i << ".png";
loadfile (name.str());
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900