WIN32_FIND_DATA FileNAme不输出文件名,而是输出十六进制代码 [英] WIN32_FIND_DATA FileNAme doesn't put out the filenames but instead put's out HEx-Codes
问题描述
我试图获取像这样的文件夹中所有文件的完整列表:
#include< Windows.h> ;
#include< iostream>
#include< stdio.h>
使用命名空间std;
void main()
{
HANDLE dateiHandle;
WIN32_FIND_DATA wfindD;
dateiHandle = FindFirstFile(L E:\\Roman\\PIC\\funpics\\ *,& wfindD);
do
{
cout<< wfindD.cFileName<<恩德尔
},而(FindNextFile(dateiHandle,& wfindD));
FindClose(dateiHandle);
而(1)
{
}
}
,我不知道为什么会这样:
00AFFCCC
00AFFCCC
00AFFCCC
00AFFCCC
00AFFCCC
00AFFCCC
00AFFCCC
00AFFCCC
00AFFCCC
00AFFCCC
00AFFCCC
00AFFCCC
00AFFCCC
00AFFCCC
00AFFCCC
TCHAR
的类型将定义为 wchar_t
(默认的最新版本) Visual Studio)。 std :: cout
对于 wchar_t *
没有任何特殊处理,因此会重新使用<$ c $ operator<<
的c> void * 重载,仅打印指向十六进制数字的内存地址。使用 std :: wcout
代替,对于 wchar_t,它确实具有 operator<<
重载*
,并会像您期望的那样打印字符串。 作为一个注释,如果您始终明确使用Win32函数和处理字符串的结构的名称(对于ANSI)或W(对于宽)。为了支持非ascii字符串,通常最好使用W版本。在这种情况下, FindFirstFileW
, FindNextFileW
和 WIN32_FIND_DATAW
。 FindClose
不直接与字符串交互,因此没有A或W版本。
I tried to get a full list of all the files in a folder like this:
#include<Windows.h>
#include<iostream>
#include<stdio.h>
using namespace std;
void main()
{
HANDLE dateiHandle;
WIN32_FIND_DATA wfindD;
dateiHandle = FindFirstFile(L"E:\\Roman\\PIC\\funpics\\*", &wfindD);
do
{
cout << wfindD.cFileName << endl;
} while (FindNextFile(dateiHandle, &wfindD));
FindClose(dateiHandle);
while (1)
{
}
}
and I can't figure out why the results are like this:
00AFFCCC
00AFFCCC
00AFFCCC
00AFFCCC
00AFFCCC
00AFFCCC
00AFFCCC
00AFFCCC
00AFFCCC
00AFFCCC
00AFFCCC
00AFFCCC
00AFFCCC
00AFFCCC
00AFFCCC
TCHAR
will be typedefed to wchar_t
if you have unicode support enabled in your project (the default recent versions of Visual Studio). std::cout
doesn't have any special handling for a wchar_t*
and falls back on the void*
overload for operator<<
, which just prints the memory address pointed to as a hex number. Use std::wcout
instead, which does have an operator<<
overload for wchar_t*
, and will print the strings like you expect.
As a side note, you'll have fewer surprises if you always explicitly use the A (for ANSI) or W (for wide) names for Win32 functions and structures that handle strings. To support non-ascii strings, you're generally better off using the W versions. In this case, FindFirstFileW
, FindNextFileW
, and WIN32_FIND_DATAW
. FindClose
doesn't directly interact with strings, so there's no A or W version of it.
这篇关于WIN32_FIND_DATA FileNAme不输出文件名,而是输出十六进制代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!