i have my file input
like this
ifstream inFile;
inFile.open(fileName.c_str());

and i cin >> fileName;
i want the output file name to be the input filename with .dat added to it
eg if fileName was c:/tmp/test.txt
i want the output to be c:/tmp/test.txt.dat

anyone know how i can do this everything ive tried isnt working

Try this:

#include <sstream>
string filename;
stringstream ss;
cin >> filename;
ss<<filename<<".dat";
outFile.open(ss.str().c_str());

The first str() gets the string from the string stream and the c_str() you already know.
(fill in the name of your own output file for outFile)

After further consideration I'm not sure why CP's solution would not work. What was the specific error you were getting?

Edited 6 Years Ago by jonsca: n/a

(fill in the name of your own output file for outFile)

Was incorrect, my apologies. I had meant to say the name of your output filestream for outFile.

Edited 6 Years Ago by jonsca: n/a

This question has already been answered. Start a new discussion instead.