Making code (more) cross platform

I am trying to make my (currently working on windows) code a bit more platform independent. This small snippet is for opening a text file (for reading/writing).

As with modern pcs many files are stored as unicode. Now In this question I am especially wondering what the right way to open such a file is. (Where the filename may be unicode).

On windows, using microsoft visual studio, I used

char* filename("c:xD0x92.txt");

#ifdef _WIN32
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
#else
std::wstring_convert<std::codecvt_utf8<wchar_t>> converter; 
//non windows wstring = utf8
#endif

std::wstring wfilename(converter.from_bytes(filename));


std::fstream fstream(wfilename);

However I just now realized this isn't standard C++11, instead a visual studio (only?) extension. However when I try on windows to first convert the widestring to an UTF-8 std::string and open the file that way the fstream doesn't recognize the filename.
So what is the cross platform solution? - Should I just expect std::fstream to always accept a widestring input? Or should I expect this on windows always?

And if possix systems don't use widestrings for their directories; what do they use?

链接地址: http://www.djcxy.com/p/54646.html

上一篇: 如何创建一个不存在的目录?

下一篇: 使代码(更多)跨平台