Wicelo
Wicelo

Reputation: 2426

Visual Studio how to ifstream in debugging mode

I'm trying to open a stream in debugging mode with visual studio but the following piece of code throw an exception meaning that it failed to open :

ifstream test ("./file"); if (!test){ throw runtime_error("failed"); }

So how can I make it work ?

Upvotes: 0

Views: 273

Answers (1)

paxdiablo
paxdiablo

Reputation: 882196

Check that the file exists. Since it's an ifstream, it's trying to open an existing file for input.

If the file doesn't exist, it will fail.

And keep in mind, it will try to open the file in your current directory. That may not be what you think it is, you can (temporarily) use something like system("cd") into your code (before the declaration of test) to see what it is.

Or, if you prefer not to call an external program, you can look into _getcwd(), which will give you the same information.

Upvotes: 1

Related Questions