Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

stdout and stderr character encoding

i working on a c++ string library that have main 4 classes that deals with ASCII, UTF8, UTF16, UTF32 strings, every class has Print function that format an input string and print the result to stdout or stderr. my problem is i don't know what is the default character encoding for those streams.

for now my classes work in windows, later i'll add support for mac and linux so if you know anything about those stream encoding i'll appreciate it.

so my question is: what is the default encoding for stdout and stderr and can i change that encoding later and if so what would happens to data stored there?

thank you.

like image 305
Muhammad Avatar asked Sep 03 '25 03:09

Muhammad


1 Answers

stdout and stderr use "C" locale. "C" locale is netural, and in most system translated into the current user's locale. You can force the program to use a specific locale using setlocale function:

// Set all categories and return "English_USA.1252"
setlocale( LC_ALL, "English" );
// Set only the LC_MONETARY category and return "French_France.1252"
setlocale( LC_MONETARY, "French" );
setlocale( LC_ALL, NULL );

The locale strings supported are system and compiler specific. Only "C" and "" are required to be supported.

http://www.cplusplus.com/reference/clibrary/clocale/

like image 141
cuteCAT Avatar answered Sep 05 '25 22:09

cuteCAT