Stdout and stderr standard encoding

i is working on a C ++ string library that has 4 main classes that deal with ASCII, UTF8, UTF16, UTF32 strings, each class has a Print function that formats the input string and prints the result to stdout or stderr. my problem is that i don't know what the default character encoding for these streams is.

now my classes work on Windows, later I will add support for mac and linux, so if you know anything about this stream encoding, I would 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 happens to the data stored there?

thanks.

+2


a source to share


2 answers


stdout and stderr use the "C" locale. The "C" locale is netural, and in most cases the system translates to the user's current locale. You can force the program to use a specific language with the function setlocale

:

// 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 );

      



Supported language strings are system and compiler dependent. Only "C" and "" are required for support.

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

+3


a source


You can take a look at this "SO" answer (most answered answer).

This is not really your question, but it is necessarily related and provides a lot of useful information.



I'm not an expert here, but I think we can assume that you should use std::cout

whenever you use std::string

and std::wcout

whenever you usestd::wstring.

0


a source







All Articles