Equivalent of MSVC++ _wrename in linux g++?

2019-09-02 11:36发布

问题:

Does anyone know if an equivalent of MSVC _wrename exist in linux g++ ? (equivalent of cstdio file rename function using const wchar_t* instead of const char* as parameter type for unicode use)

Thanks !

回答1:

The point is that most filesystems other than NTFS store their filenames in byte-strings. There is usually no explicit notion of encoding, but the filenames have to be strings of non-zero bytes terminated by a zero. So on all such systems, filesystem functions just take char* arguments for filenames, and you have to figure our yourself how to handle encoding issues (should there be any).

Windows is special because filenames in NTFS are null-terminated strings of 16-bit units. This goes hand-in-hand with the 16-bit wchar_t type on Windows and various _w* filesystem functions.



回答2:

That's platform specific. I'm afraid you'll have to convert your const wchar_t* to const char* somehow. On Linux, i think you can use the iconv function.

EDIT: Boost probably has something for this