gpt4 book ai didi

c++ - 如何正确使用 GetModuleFileName?

转载 作者:IT老高 更新时间:2023-10-28 21:55:29 32 4
gpt4 key购买 nike

以下代码:

#include <iostream>
#include <Windows.h>

using namespace std;

int main ()
{ LPWSTR buffer; //or wchar_t * buffer;
GetModuleFileName(NULL, buffer, MAX_PATH) ;
cout<<buffer;
cin.get();
cin.get();

}

应该显示程序执行的完整路径。但是在 VS 2012 中我得到了错误:

uninitialized local variable 'buffer' used

代码有什么问题?

最佳答案

你需要给它一个可以容纳一些字符的缓冲区;

 wchar_t buffer[MAX_PATH]; 

例如。

关于c++ - 如何正确使用 GetModuleFileName?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18783087/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com