static void GetFilesFromDir(std::string dir, std::vector<std::string>& items)
{
WIN32_FIND_DATA findData;
HANDLE hFind=FindFirstFile((dir+"\\*").c_str(), &findData); //1 error
do
{
if(hFind != INVALID_HANDLE_VALUE)
{
std::string sFileName = findData.cFileName; //2 error
LPCSTR lp(sFileName.c_str());
if(sFileName == "." || sFileName == "..")
{} //do nothing
else if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
GetFilesFromDir(dir+"\\"+sFileName, items);
else
items.push_back(dir+"\\"+sFileName);
}
} while (FindNextFile(hFind, &findData));
}
所以这是我的简单功能,我只是从另一个项目到新项目。并且它无缘无故地抛出错误,特别是因为它适用于其他项目......
1>c:\users\prog\documents\visual studio 2010\projects\vampire stealth\vampire stealth\smallfunctions.h(22): error C2664: 'FindFirstFileW' : cannot convert parameter 1 from 'const char *' to 'LPCWSTR'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>c:\users\prog\documents\visual studio 2010\projects\vampire stealth\vampire stealth\smallfunctions.h(27): error C2440: 'initializing' : cannot convert from 'WCHAR [260]' to 'std::basic_string<_Elem,_Traits,_Ax>'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ax=std::allocator<char>
1> ]
1> No constructor could take the source type, or constructor overload resolution was ambiguous
任何人都对错误有什么看法?我完全不知道它。
答案 0 :(得分:1)
第一个错误:
...(dir+L"\\*").c_str()...
第二个错误:
std::wstring wFileName = findData.cFileName;
我认为您已为项目设置了UNICODE标志,因此您需要使用宽字符。 wchar_t inte和char和wstring而不是string。