Opening Files in a For Loop

I am trying to use the following code as a guide:

1
2
const char* fileName = testName.c_str();
indata.open(fileName);


My question is, how can I use this to open a new file within every iteration of a for loop? For example, suppose my files are named 'image1.png', 'image2.png', etc.

I'm assuming I can't assign the (const) variable again in a for loop, but can I define the variable inside the loop? Any other way to accomplish this?

Thanks.
If you're going to get the const char* from the string class, you may as well simply append the number to the end of the string and then foo.c_str();
Topic archived. No new replies allowed.