open file

hello im new to c++
normally i would open a file for appending
with a code that looks like

outfile = fopen("test.txt""a");
but now i want to use a variable file name like

string_str()
in place of "test.txt

can anyone please advise a piece of code that might help
Well that's the C way of doing things.

To open a file in C++ for append with a variable path would be

1
2
string path = "some_file.txt";
ofstream outFile( path.c_str(), ios_base::app );


Of course include the proper headers
1
2
#include <fstream>
#include <string> 


If you get stuck you can always read the documentation on this site.

http://cplusplus.com/reference/iostream/fstream/
http://cplusplus.com/reference/string/string/
There is also a tutorial on file I/O: http://www.cplusplus.com/doc/tutorial/files/
Topic archived. No new replies allowed.