Convert int to string for use as FILENAME
Code:
void scanimg(IplImage *scnimg){
for(int k=0; k<SCL_NUM; k++){
ofstream localfile;
char s1[20];
std::stringstream ss1;
ss1<<k<<".csv";
s1=ss1.str();
localfile.open(s1);
for(int i=SCANRAD; i<H-SCANRAD; i+=5){
for(int j=SCANRAD; j<W-SCANRAD; j+=5){
scnmakevec(scnimg,i,j);
localfile<<crocor(scenevec,scalevecs[k])<<",";
}
localfile<<endl;
}
localfile.close();
}
}
I want the files to be named as "1.csv", "2.csv" and so on. The error I get is:
Code:
cannot convert from 'std::basic_string<_Elem,_Traits,_Ax>' to 'char [20]'
Does anyone know a way around?
Re: Convert int to string for use as FILENAME
Arrays are not assignable.
Why introduce arrays, when you have the string already in the stream?
Code:
std::stringstream ss1;
ss1<<k<<".csv";
localfile.open(ss1.str().c_str());
Regards,
Paul McKenzie
Re: Convert int to string for use as FILENAME