J .A
J .A

Reputation: 63

Open a file in current directory

I'm trying to open a file where my program runs, I could open a file in directories like this:

myfile.open("D:\\users.txt");

But I want to open this file:

myfile.open("users.txt");

users.txt is placed where my program is.

Upvotes: 0

Views: 2868

Answers (3)

Lightness Races in Orbit
Lightness Races in Orbit

Reputation: 385395

users.txt is placed where my program is.

The current working directory of your process may not be where your program executable is. The two are not bound together.

Upvotes: 5

Chad
Chad

Reputation: 3018

I recommend reading up on Naming Files, Paths, and Namespaces to give you a better understanding how Win32 API handles File paths, and also Namespaces. It will help you in the long run when you need to open USB and Serial connections to external devices.

Upvotes: 0

Giwrgos Tsopanoglou
Giwrgos Tsopanoglou

Reputation: 1215

This:

myfile.open("users.txt");

should work just fine. However, I have encountered situations where the program could not read the file. That was due to the white spaces being included within the full path:

eg: "C:\Folder1\Folder 2\file.txt"

Make sure you don't have any white spaces there...

Upvotes: 0

Related Questions