C++ UTF-8 in CP866



  • I'm writing a library for the printer. UTF-8 is submitted to the entrance. Printer prints a CP866(kirillian). How to transform UTF-8 into CP866? Is there any special functions?



  • ifstream file("text.txt");
    char pszCode[30];
    file.getline(pszCode, 30);
    BSTR    bstrWide;
    char   pszAnsi[50];
    int     nLength;
    char* text = "";
    
    nLength = MultiByteToWideChar(CP_UTF8, 0, pszCode, strlen(pszCode) + 1, NULL, NULL);
    bstrWide = SysAllocStringLen(NULL, nLength);
    
    MultiByteToWideChar(CP_UTF8, 0, pszCode, strlen(pszCode) + 1, bstrWide, nLength);
    
    nLength = WideCharToMultiByte(CP_OEMCP, 0, bstrWide, -1, NULL, 0, NULL, NULL);
    WideCharToMultiByte(CP_OEMCP, 0, bstrWide, -1, pszAnsi, nLength, NULL, NULL);
    SysFreeString(bstrWide);
    
    cout << pszAnsi << endl;
    

    In general, we used this method, as VladD advised, in principle everything works, although of course I did not understand how these two functions work before the end. But thanks anyway!




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2