Search code examples
c++visual-c++working-directory

How do I find the current directory?


I am trying to read a file which I read previously successfully. I am reading it through a library, and I am sending it as-is to the library (i.e. "myfile.txt"). I know that the file is read from the working/current directory.

I suspect that the current/working directory has changed somehow. How do i check what is the current/working directory?


Solution

  • Since you added the visual-c++ tag I'm going to suggest the standard windows function to do it. GetCurrentDirectory

    Usage:

    TCHAR pwd[MAX_PATH];
    GetCurrentDirectory(MAX_PATH,pwd);
    MessageBox(NULL,pwd,pwd,0);