我取得了很大进展,但我有 2 个问题让我放慢了好几天。最大的问题是我想将 FindFileData.cFileName
保存为字符串,但我不能!有什么帮助吗?
最佳答案
我从这里复制了这个:How to convert wstring into string? 它将 wstring 直接转换为字符串(包括 FindFileData.cFileName)。有什么更好的建议或有用的意见吗?
#include <clocale>
#include <locale>
#include <string>
#include <vector>
inline std::string narrow(std::wstring const& text)
{
std::locale const loc("");
wchar_t const* from = text.c_str();
std::size_t const len = text.size();
std::vector<char> buffer(len + 1);
std::use_facet<std::ctype<wchar_t> >(loc).narrow(from, from + len, '_', &buffer[0]);
return std::string(&buffer[0], &buffer[len]);
}
关于c++ - 无法将 FindFileData.cFileName 转换为字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16195321/