apaaaan
apaaaan

Reputation: 31

Changing a filename by incrementing

So I have this for loop:

for (int x = 1; x < 13; x++)
{
    inputImages.push_back(Image(3264, 2448));
    inputImages[x] = readPPM("Images/ImageStacker_set1/IMG_1.ppm");
}

What i'm trying to do is to add the loop variable to the filename so it will increment the filename where it says:

IMG_1.ppm

To replace the 1 with the variable x so each time it loops it will add a new file to the array.

I tried something like this but it didn't work:

inputImages[x] = readPPM("Images/ImageStacker_set1/IMG_"<< x <<".ppm");

Does anyone have a method for doing this?

Upvotes: 2

Views: 195

Answers (1)

Jake Freeman
Jake Freeman

Reputation: 1698

A very quick way to solve this:

inputImages[x] = readPPM(string("Images/ImageStacker_set1/IMG_" + to_string( x ) + ".ppm").c_str());

Upvotes: 3

Related Questions