How To: Save Each Image With a Unique Filename#
Question#
How do I save each image as "image_1.png", "image_2.png", and so on in my API?
Solution#
There are many ways to approach this task, but here are two of the easiest:
-
Save the image using
itoa()
to convert the image number to a string for a unique file name. This might not work on Linux, asitoa()
is a non-standard C++ function. -
Save the image using
sprintf()
to convert the image number to a string for a unique file name. This is more portable and will work on Linux, but adds one more line of code.