我正在編譯我的庫,它支持unicode,現在我遇到了需要打開ASCII數據文件的問題,但當然文件名是widechars。那麼我怎麼做到這一點?使用unicode名稱打開輸入文件流,但使用ASCII數據
當我使用此代碼:
std::wstring s = L"path";
std::ifstream fl;
fl.open(s.c_str(), std::fstream::in);
然後我得到這個錯誤:
error: no matching function for call to 'std::basic_ifstream<char>::open(const wchar_t*, const openmode&)'
當我使用
std::wifstream fl;
fl.open(s.c_str(), std::fstream::in);
我得到同樣的錯誤(? ??)
error: no matching function for call to 'std::basic_ifstream<wchar_t>::open(const wchar_t*, const openmode&)'
即便如此,當我使用std::wifstream
時,流期望輸入數據是否也是unicode?如果是這樣,那麼我將不得不使用std::ifstream
,但我仍然需要傳遞它的寬字符串,或者以某種方式將其轉換爲ASCII。什麼是正確的方法來做到這一點?
我使用MingW gcc 4.8.3。
mingw32-g++.exe -pedantic -std=c++11 -Wextra -Wall -g -D_UNICODE -D_WIN32 -Iinclude -c propertyfile.cpp -o propertyfile.o
這是爲什麼downvoted?轉換是錯誤的,還是僅僅是因爲大括號錯誤? – Devolus
我不知道,這是完全合法的C++ 11代碼。 http://coliru.stacked-crooked.com/a/ab322f7b56e94c71 – galop1n
因爲答案的每個方面都不正確? – Simple