質問

I use mingw compiler. How to convert wchar_t to char ?

Data(HWND hwnd,  wchar_t szFileName[MAX_PATH])
{
    string sIn;
    ifstream infile;
    infile.open(szFileName);
    infile.seekg(0,ios::beg);

    // fill vector with file rows
    while ( getline(infile,sIn ) )
    {
       fileRows.push_back(sIn);
    }
}

I would like to convert wchar_t szFileName to char szFileNameChar.

役に立ちましたか?

解決

string str("i'm char[]");
wstring wstr(str.begin(), str.end());

wstring wstr(L"i'm wchar_t[]");
string str(wstr.begin(), wstr.end());

To see a detailed explanation, please refer to the following post: std::wstring VS std::string

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top