0

我想将strFileNotifyInfo[1].FileName (Wchar_t) 转换为字符串,以便我可以看到文件路径。但我不能让它工作。

这是我的代码:

while(TRUE)
{
    if( ReadDirectoryChangesW( hDir, (LPVOID)&strFileNotifyInfo, sizeof(strFileNotifyInfo), FALSE, FILE_NOTIFY_CHANGE_LAST_WRITE || FILE_NOTIFY_CHANGE_CREATION, &dwBytesReturned, NULL, NULL) == 0)
    {
        cout << "Reading Directory Change" << endl;
    }
    else
    {

        cout << ("File Modified: ") << strFileNotifyInfo[1].FileName << endl;
        cout << ("Loop: ") << nCounter++ << endl;
    }
}
4

2 回答 2

0

您还应该记住FileName 不是以 null 结尾的

WCHAR* filename_w = strFileNotifyInfo[1].FileName;
DWORD filename_len = strFileNotifyInfo[1].FileNameLength;
std::string filename(filename_w, filename_w + filename_len);
std::cout << "File Modified: " << filename << std::endl;
于 2013-02-10T17:15:47.177 回答
0

wcout在处理宽字符数据时使用。

std::wcout << L"File Modified: " << strFileNotifyInfo[1].FileName << std::endl;
于 2013-02-10T16:47:40.857 回答