Passing full path as argument when it contains variable strings

Hi,

In directory "inoutfiles", I have folders fold0001, fold0002 and so on. Every folder has corresponding file file0001.txt, file0002.txt and so on. I want to perform a certain action on multiple files in one go. The cpp file is in the same directory as "inoutfiles".

This is my code :

char fold[30], file[30], pfold[20] = {'i','n','o','u','t','f','i','l','e','s'};
string str1 = "fold", str2 = "file", ext = ".txt", pf = "inoutfiles";
int size1, size2;
string padnum, index, foldername, filename;
for(int i=10005; i<10010; i++)
{
stringstream ss;
ss << i;
index = ss.str();
padnum = index.substr(1,index.length()-1);
foldername = str1 + padnum;
filename = str2 + padnum + ext;
size1 = foldername.size();
for(int j=0; j<=size1; j++) fold[j]=foldername[j];
size2 = filename.size();
for(int k=0; k<=size2; k++) file[k]=filename[k];
f.open(pfold/fold/file);
...
}

The error is operator '/' is binary. How to get around this?

Also, f.open((pf.c_str())/(foldername.c_str())/(filename.c_str())) is not working.

Hi,

My friend pointed out the mistake in my code and I'm posting the correction here. It was so easy yet I don't know how it was overlooked.

Outside loop :

string path = "inoutfiles";

Inside loop :

path = path + "/" + foldername + "/" + filename;
f.open(path.c_str());