Click to See Complete Forum and Search --> : Outputting to a file question


daduke40
March 22nd, 2008, 09:39 PM
I have the piece of code:

outfile.open (filename.c_str());

where filename is the filename.txt provided by the user.

However, how would I add .csv to end of that so I can change the file extension and create a new file?

so basically the outfile name would look like this

filename.txt.csv

-jeff

Plasmator
March 22nd, 2008, 09:58 PM
There are quite a few ways of doing this.
Assuming that filename contains expected data, this is one option:
outfile.open(std::string(filename + ".csv").c_str());

7stud
March 23rd, 2008, 12:08 AM
string str;
str = "hello";
str += " world";
cout<<str<<endl; //hello world