Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cannot convert FindFileData.cFileName to string

Tags:

c++

winapi

I am making great headways but I have 2 problems that have been slowing me down for days. The biggest is that I want to save FindFileData.cFileName as string but I cannot ! Any help ?

like image 891
alwaystudent Avatar asked Oct 22 '22 11:10

alwaystudent


1 Answers

I copied this from here: How to convert wstring into string? It converts wstring directly to string ( including FindFileData.cFileName). Any better suggestion or any useful comment ?

#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]);
}
like image 75
alwaystudent Avatar answered Oct 27 '22 11:10

alwaystudent