简体   繁体   中英

Printing libcurl response in Windows command prompt

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 (eg \д). 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?

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

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM