Convert const char* to const wchar_t*

后端 未结 3 1313
有刺的猬
有刺的猬 2021-02-09 08:30

I am trying to create a program with Irrlicht that loads certain things from a configuration file written in Lua, one of which is the window title. However, the lua_tostri

3条回答
  •  我寻月下人不归
    2021-02-09 09:19

    There are multiple questions on SO that address the problem on Windows. Sample posts:

    1. char* to const wchar_t * conversion
    2. conversion from unsigned char* to const wchar_t*

    There is a platform agnostic method posted at http://ubuntuforums.org/showthread.php?t=1579640. The source from this site is (I hope I am not violating any copyright):

    #include 
    #include 
    #include 
    #include 
    using namespace std ;
    
    wstring widen( const string& str )
    {
        wostringstream wstm ;
        const ctype& ctfacet = use_facet>(wstm.getloc()) ;
        for( size_t i=0 ; i& ctfacet = use_facet>(stm.getloc());
    
        // Correct code.
        const ctype& ctfacet = use_facet>(stm.getloc());
    
        for( size_t i=0 ; i

提交回复
热议问题