简体   繁体   中英

_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.

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM