我用FindFirstFile(...)
函數編寫了查找文件的程序。但是,當我嘗試打印此功能的輸出時,控制檯窗口中會顯示幾串未知字符。 我看了一些帖子,寫的是試用wcout
而不是cout
。我嘗試了一下,但沒有幫助。我認爲,問題在於ANSI和UNICODE編碼之間的區別。有人能幫助我嗎?我會非常感謝任何幫助!C++,FindFirstFile的輸出()
這裏是我的代碼:
#include "FindFile.h"
#include <iostream>
using namespace std;
void FindFileCl::Execute(Input * input, Response * response)
{
WIN32_FIND_DATAA FindFileData;
HANDLE h = FindFirstFileA((input->FileName).c_str(), // name of the file
&FindFileData);
if (h)
{
cout << "Search Results:\n";
cout<<(FindFileData.cFileName);
CloseHandle(h);
}
else
{
cerr << "File is NOT found:" << GetLastError() << "\n";
}
}
嘗試使用'FindFirstFile'而不是'FindFirstFileA',並以Unicode編譯您的程序。在控制檯中使用'chcp 65001'將代碼頁更改爲UTF-8。 –
謝謝你的回答,Nemanja Boric。我試圖使用FindFirstFile而不是FindFirstFileA,但隨後它會導致函數的第一個參數出現問題,所以我使用FindFirstFileA。 – Victor
哦,您需要使用'WIN32_FIND_DATA'而不是'WIN32_FIND_DATAA'。 –