How to read file which contains \uxxxx in vc++

后端 未结 4 1879
遇见更好的自我
遇见更好的自我 2020-12-12 00:14

I have txt file whose contents are:

\\u041f\\u0435\\u0440\\u0432\\u044b\\u0439_\\u0438\\u043d\\u0442\\u0435\\u0440\\u0430\\u043a\\u0442\\u0438\\u0432\

4条回答
  •  误落风尘
    2020-12-12 01:07

    Check this code :) Windows SDK has it already for you, MS geeks thought for this too, you can find more details in this post: http://weblogs.asp.net/kennykerr/archive/2008/07/24/visual-c-in-short-converting-between-unicode-and-utf-8.aspx

    #include 
    #include 
    
    #define ASSERT ATLASSERT
    
    int main()
    {
        const CStringW unicode1 = L"\u041f and \x03A9"; // 'Alpha' and 'Omega'
    
        const CStringA utf8 = CW2A(unicode1, CP_UTF8);
    
        ASSERT(utf8.GetLength() > unicode1.GetLength());
    
        const CStringW unicode2 = CA2W(utf8, CP_UTF8);
    
        ASSERT(unicode1 == unicode2);   
    
        return 0;
    }
    

    This code has been tested by me and it works fine.

提交回复
热议问题