_fullpath 在 Visual Studio C++ 中给出十六进制值
_fullpath Giving Hex Value in Visual Studio C++
我正在尝试找出我当前的工作目录。我试过同时使用 _fullpath
和 _getcwd
作为 <direct.h>
的一部分。但是,它给我的只是一个 8 字节的十六进制值(例如 5504CA90
)。
为什么给我这个,我怎样才能得到正确的 cwd?我在 C++ 中使用 Visual Studio 2015。
我的代码如下所示:
std::cout << "CWD: " << _fullpath << "\n";
它给了我这个输出:
CWD: 0F8CCA90
但是,每次我 运行 它都会给我一个不同的十六进制值。
您没有调用 _fullpath
/getcwd
方法。您的代码将简单地打印其地址。这是十六进制值,您在控制台输出中得到。要调用 方法,您必须提供其参数:
char *_getcwd( char *buffer, int maxlen );
char szPath[255];
char* pszPath = _getcwd(szPath, sizeof(szPath)/sizeof(char));
if(pszPath)
std::cout << pszPath << std::endl;
我正在尝试找出我当前的工作目录。我试过同时使用 _fullpath
和 _getcwd
作为 <direct.h>
的一部分。但是,它给我的只是一个 8 字节的十六进制值(例如 5504CA90
)。
为什么给我这个,我怎样才能得到正确的 cwd?我在 C++ 中使用 Visual Studio 2015。
我的代码如下所示:
std::cout << "CWD: " << _fullpath << "\n";
它给了我这个输出:
CWD: 0F8CCA90
但是,每次我 运行 它都会给我一个不同的十六进制值。
您没有调用 _fullpath
/getcwd
方法。您的代码将简单地打印其地址。这是十六进制值,您在控制台输出中得到。要调用 方法,您必须提供其参数:
char *_getcwd( char *buffer, int maxlen );
char szPath[255];
char* pszPath = _getcwd(szPath, sizeof(szPath)/sizeof(char));
if(pszPath)
std::cout << pszPath << std::endl;