fstream::open can't find file?

Hello. I'm trying to open a file named "global.wdf" for editing. However, is_open() is always returning false. I'm putting global.wdf into my TestProject\Debug folder (which is currently the same directory the .exe file resides in), but is_open() still returns false. Any idea what I'm doing wrong?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <iostream>
#include <fstream>
#include <string>

using namespace std;

inline void addl(string str);

int main()
{
	addl("Welcome!");

	fstream f;
	f.open("global.wdf", ios::binary);

	if (f.is_open())
	{
		f.close();
		addl("Successfully opened global.wdf.");
	}
	else
	{
		addl("Unable to open global.wdf.");
	}

	addl("\nPress enter to close the program.");
	getchar();
	return 0;
}

inline void addl(string str)
{
	cout << str << '\n';
}
If you're running the program through the debugger, you should know that the working directory (which affects the behavior of file-related functions when relative paths are given) may not necessarily be the directory the executable is in.
I've tried putting global.wdf in pretty much every folder of the project. Even when running the executable directly (outside of the IDE), the program still can't find the file.
closed account (j3Rz8vqX)
You had it previously in:
...\TestProject\Debug


Try it in the
TestProject
directory.
I tried that as well. is_open() is still returning false.

The IDE I'm using is Microsoft Visual Studio Express 2013 for Windows Desktop, if that means anything.
closed account (j3Rz8vqX)
What do you want.....
f.open("global.wdf", ios::in|ios::out|ios::binary);

Out? In? or both?(as the above applied)

Cannot open without the specific =D

Have a good day; make sure to have the file where the project file is, if running from an ide.
Adding the ios::in and ios::out flags fixed my problem and now the file actually opens! Thank you very much!
closed account (j3Rz8vqX)
Your welcome.
Topic archived. No new replies allowed.