Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Concatenating an integer to a string [duplicate]

Tags:

c++

I am trying to save a sequence of images in visual studio 2008,all with the prefix of "Image". the only differentiating factor should be their number. for example if I am gonna save 10 images then the situation should be

i=1;
while(i<10)
{
cvSaveImage("G:/OpenCV/Results/Imagei.jpg",img2);
i++
//"i" is gonna be different every time
}

so I need to concatenete the integer with the string... looking forward to the answer...

like image 262
Aayman Khalid Avatar asked Dec 27 '22 07:12

Aayman Khalid


1 Answers

The c++ way (pre-c++11) would be:

#include <sstream>
...
ostringstream convert;
convert << "G:/OpenCV/Results/Image" << i << ".jpg";
cvSaveImage(convert.str().c_str(), img2);
i++;
like image 144
StoryTeller - Unslander Monica Avatar answered Jan 09 '23 08:01

StoryTeller - Unslander Monica