Search code examples
c++visual-studiovisual-studio-2015directorygetcwd

_fullpath Giving Hex Value in Visual Studio C++


I'm trying to find out what my crrent working directory is. I've tried using both _fullpath and _getcwd as part of <direct.h>. However, all it gives me is an 8-byte hex value (such as 5504CA90).

Why is it giving me this, and how can I get the correct cwd? I am using Visual Studio 2015 in C++.

My code looks like this:

std::cout << "CWD: " << _fullpath << "\n";

And it gives me this output:

CWD: 0F8CCA90

However, it gives me a different hex value every time I run it.


Solution

  • You are not calling _fullpath/getcwd method. Your code will simply print its address. This is the hex value, you are getting in the console output. To call method you have to supply its parameters:

    char *_getcwd( char *buffer, int maxlen );

    char szPath[255];
    char* pszPath = _getcwd(szPath, sizeof(szPath)/sizeof(char));
    if(pszPath)
      std::cout << pszPath << std::endl;