There are several ways to do this. Depending on your environment and the compiler / standard library / other libraries available, you have at least three options:
- Use std :: locale and std :: codecvt <> facet;
- use C language functions such as std :: mbstowcs ();
- use third-party functions like iconv () on * nix or WideCharToMultiByte () on Windows.
Do you really need to do the conversion?
You should understand that often (especially on Windows) converting from a wchar_t string to a char string is a lossy conversion. The character set used by the system for char strings is often not UTF-8. For instance. if you convert the file name with national characters or in some Asian language to a char string, most likely you will get something that will not be really useful for accessing the source file.
source share