Path of output file
Nov 25, 2013 at 3:02pm UTC
Hello everybody!I have a question, for the output file of my code.
I use the ofstream to create a file like this...
1 2
ofstream myOutFile;
myOutFile.open("output.txt" );
What i want is to print the path of the output file so the user will
know where the file is.Please help guys.
Nov 25, 2013 at 3:08pm UTC
Why not specify the path yourself, e.g.
1 2
char filename[] = "C:\\files\\output.txt" ;
ofstream myOutFile(filename);
and then simply print the filename.
Nov 25, 2013 at 3:30pm UTC
This is a good way to do it but i dont want to change the path of the file
i simply want to take the path and print it.I try to do it with GetModuleFileName
but i can't.
Nov 25, 2013 at 3:49pm UTC
Well, I'm not sure whether there's a standard way to do this. Here's a way which works with my compiler on a Windows system.
1 2 3 4 5 6 7 8 9 10 11 12 13
#include <iostream>
#include <dir.h>
using namespace std;
int main()
{
char buffer[512];
getcwd(buffer, 512);
cout << "The current directory is: " << buffer << endl;
return 0;
}
Topic archived. No new replies allowed.