我现在在Qt Creator中使用MingW32 G ++编译器。标准C++不能在Qt Creator中编译
我移植过从代码块工作代码到Qt,所以我可以使用Qt的网络功能,但在代码的那一刻我口时,出现的错误进行编译:
C:\software\Qt\AutoUpload\main.cpp:90: error: cannot convert 'std::__cxx11::string {aka std::__cxx11::basic_string<char>}' to 'LPCWSTR {aka const wchar_t*}' for argument '1' to 'void* FindFirstFileW(LPCWSTR, LPWIN32_FIND_DATAW)'
HANDLE handle = FindFirstFile(dir, &search_data);
的一段代码,让这个错误是8号线:
如那些1 vector<string> getFilesInDir(string directory)
2 {
3 vector<string> filenames;
4 string dir = string(directory + "\\*");
5
6 WIN32_FIND_DATA search_data;
7 memset(&search_data, 0, sizeof(WIN32_FIND_DATA));
8 HANDLE handle = FindFirstFile(dir.c_str(), &search_data);
9 while (handle != INVALID_HANDLE_VALUE)
10 {
11 if (FindNextFile(handle, &search_data) == FALSE) break;
12 if (search_data.cFileName == string(".") || search_data.cFileName == string(".."))
13 {
14 cout << "Ignoring..." << endl;
15 continue;
16 }
17 filenames.push_back(search_data.cFileName);
18 cout << search_data.cFileName << endl;
19 }
20
21 FindClose(handle);
22 return filenames;
23 }
其他问题发现here和here状态,这是一些问题与Unicode编码的Windows API与LPCWSTR
类型一起使用,但此答案不完整或不正确。我的CodeBlocks和Qt Creator编码设置都是UTF-8,而不是Unicode或任何其他编码方法。
如果这是一个Unicode问题,此代码将而不是编译在Visual Studio或CodeBlocks中,但它是无论如何。 Qt中只有只有环境它不能完美编译。
什么是Qt Creator这样做突然使这个代码无法使用?
错误消息和您显示的代码不匹配。 –
查看第二个答案。 http://stackoverflow.com/questions/8032080/how-to-convert-char-to-wchar-t – silentboy
是的。我在示例中手动添加了行号,以便我可以轻松地指出发生错误的行。 (根据代码段中的第8行,完整代码库中的第90行) 也许你应该在评论之前实际阅读问题。 – Kats