Set file directory

Okay I'm pretty new to programming and all, and I need help setting where to save the file I create to. Right now, it continues to save to the folder where the program is running from. I would really like to know how to change where is saves.

This the only chunk of the code I need help with.
1
2
3
4
5
6
7
  std::ofstream outfile (string(name+"."+type).c_str());
    const char *path="c:\test";
    std::ofstream file(path);
    
    outfile <<text<< std::endl;

    outfile.close();
You are using a fstream as if it were a string. Also, watch out for those \ backslashes. (You must use two if you want one: "c:\\test".)

1
2
3
4
std::string filename = std::string("c:/test") + "/" + name + "." + type;

std::ofstream(filename.c_str());
...

Hope this helps.
Topic archived. No new replies allowed.