I am reading filenames written in a text file into a string vector. For each file name I want to create its complete path so that I can read it. For final path I merge 'Map_PATH' and 'filenames' variables together into FileName (char array) using sprintf function.
Now on windows its shows FileName contains "/data2/worcester_000187.txt" which is what I needed. But running it on Ubuntu server gives a result ".txta2/worcester_000187" instead, it overwritten data2 partially. Text file contains file names like this i.e. Single name on each line:
worcester_000187
worcester_000192
worcester_000193
worcester_000194
worcester_000196
worcester_000197
worcester_000198
What I found that if I assign 'filename' string variable with a hard coded values say:
filename="worcester_000187";
I get the right results. But it creates problem when same filename variable gets a string values read from text file. Either there is some problem with reading with file.
Below a highlight of code is given:
char FileName[500];
char Map_PATH[]="/data2/";
vector < string > fileList;
string filename;
fstream fp;
fp.open ("ImagesListTemp.txt", ios::in);
if(!fp.is_open())
{
cerr <<"Unable to open Image Names List: "<<endl;
exit(1);
}
while (getline(fp, filename))
{
fileList.push_back(filename);
}
fp.close();
for(int i=0;i<fileList.size();i++)
{
filename=fileList[i];
// filename="worcester_000187";
sprintf(FileName,"%s%s.txt",Map_PATH,filename.c_str());
// Open File and do some operations
}