C++でu16Stringを使ったファイル名で、ifstreamを作成したいのですが
文字コードの変換がうまくいかず、困っています。
どうしたらifstreamをu16Stringの日本語パス指定で使えるようになるでしょうか。
ご指摘、よろしくお願いします。
※wstring_convertでchar16_tを引数にするのは避けます。理由はVS2015のバグです。
https://connect.microsoft.com/VisualStudio/feedback/details/1348277/link-error-when-using-std-codecvt-utf8-utf16-char16-t
c++
1 2//abc.pdfだとうまくいく 3u16string utf16Str = u"C:\a\bbb\test_file\土壇場.pdf"; 4 5 6std::wstring_convert<std::codecvt_utf8<uint16_t>, uint16_t> utf8Conv; 7 8 9std::string utf8Str = utf8Conv.to_bytes(reinterpret_cast<const uint16_t*>(utf16Str.c_str())); 10 11 12 13std::ifstream fin; 14 15 fin.open(utf8Str, ios::binary); 16 17 if (!fin) 18 { 19//日本語ファイル名の場合のみfalseになる 20 cout << "false" << endl; 21 } 22 23
回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/11/22 13:28