c++ - 无法将 FindFileData.cFileName 转换为字符串

标签 c++ winapi

我取得了很大进展,但我有 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/

相关文章:

c# - 从不使用标签控件的对话框中获取文本?

c# - 如何使用 C# 拦截 Win32 API 调用?

c++ - OpenSSL 静态库太大,有什么替代方法或方法可以减小它的大小吗?

c++ - linux套接字接收离开

C++在控制台上更改输出

python - 在 Windows 上列出串行 (COM) 端口?

c++ - 找出正在运行的应用程序的通信端口设置

c++ - C++ 中的 Lisp/Scheme DSEL

java - 使用 undefined symbol 加载 JNI 时崩溃

c++ - 如何获取特定用户的 Windows "special folder"路径?