Path for filename(ofstream)

How do I give the path name to the compiler?
Here is a portion of the code that I have written:

ifstream file;
file.open("test.txt");
I have test.txt in my computer but when I try writing the contents of this file to standard output using cout, there is nothing dispalyed. I suspect that the file is not found by the compiler.


Any ideas?
You will want to check if it opened successfully. Also note that unless you provide the directory path, it will have to be in the same directory as the executable.

1
2
3
4
5
6
7
ifstream file;
file.open("test.txt");

if (file)
  // file was opened successfully



i think the compiler does not recognize the file...this makes me wonder if i need to give the full path name?
yes, looks like the file opens correctly. in that case, the problem is contents of the file are not getting displayed.
any help here? I'm still not able to open and read the file.
how did you read data from the file?
Put "test.txt" in the same directory as the exe and run the exe from within windows explorer, not from IDE menu (working directory is not the same)



Topic archived. No new replies allowed.