gpt4 book ai didi

c++ - 为什么 lpstrFile 返回内存中的地址而不是 OPENFILENAMEW 结构中的 char 数组?

转载 作者:太空宇宙 更新时间:2023-11-04 15:06:12 25 4
gpt4 key购买 nike

这段代码应该编译没有错误你应该链接 -lcomdlg32 用于对话框。程序返回:0x22fcd868 如果我使用指针。并且应该(我认为)在对话框中返回文件用户类型的名称。

#include <windows.h>
#include <iostream>

int main() {
wchar_t szFileName[MAX_PATH] = {0};
OPENFILENAMEW ofn;
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.nMaxFile = MAX_PATH;
ofn.lpstrFile = szFileName;
GetSaveFileNameW(&ofn);

using namespace std;
cout << szFileName << endl;
cout << *szFileName << endl; // also a number not a string
}

最佳答案

如果要将 wchar_t 数组输出为空终止宽字符串,则必须使用 wcout

关于c++ - 为什么 lpstrFile 返回内存中的地址而不是 OPENFILENAMEW 结构中的 char 数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14405711/

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