0

I am trying to print out the answer I get from a curl query (UTF-8 charset), after performing the query I make a string with the following code:

size_t writeToString(char* ptr, size_t size, size_t nmemb, std::string* stringPtr) {
    stringPtr->append(ptr, nmemb*size);
    return size*nmemb;
}

When doing a cout of the string, the Unicode characters are displayed as their code (e.g. \u0434). I've tried changing the code page of the command prompt to 65001. Is it possible to print out the UTF-8 curl response in the Windows command prompt?

dda
  • 6,030
  • 2
  • 25
  • 34
SiimKallas
  • 934
  • 11
  • 23

2 Answers2

0

Have you tried storing it in a std::wstring (rather than a std::string) before cout?

This question may help: UTF8 to/from wide char conversion in STL

Community
  • 1
  • 1
Scotty
  • 2,480
  • 2
  • 16
  • 20
0

Try calling SetConsoleOutputCP(65001) and then use WriteConsole() or WriteConsoleOutput() instead of std::cout.

Otherwise, decode the UTF-8 data to UTF-16 and then convert it to Ansi before then using std::cout.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • Well, silly me, std::string doesn't magically convert UTF-8 codes from a char array. Got it working by converting them and setting the code page to 65001. – SiimKallas Jul 12 '12 at 22:35