加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-16 05:04:29 所属栏目:百科 来源:网络整理
导读:我正在取得很大进展,但我有两个问题让我放慢了几天.最大的是我想将FindFileData.cFileName保存为字符串,但我不能!有帮助吗? 解决方法 我从这里复制了这个: How to convert wstring into string? 它将wstring直接转换为字符串(包括FindFileData.cFileName)
我正在取得很大进展,但我有两个问题让我放慢了几天.最大的是我想将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]);
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读