views:

122

answers:

2

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.

A: 

You might take a look at this SO answer (most upvoted answer).

This is not exactly your question, but it is surely related and gives a lot of useful information.

I'm not expert here, but I guess we can assume you should use std::cout whenever you use std::string and std::wcout whenever you use std::wstring.

ereOn
you're right however i'm not using string or wstring i've my own string classes and each one have its internal representation and for that i can not use cout or wcout to print to stdout stream.
Muhammad alaa
I might miss something but... don't the standard `std::string` and `std::wstring` cover all possibles encodings ? Do you *really* need to create your own string classes ?
ereOn
its not just about encoding, there is too many reason that made me make my own string classes, for example in my classes i use mmx for copy and search, reference counter to not wast memory when passing by value(some times i need to), hash coding for strings and many others.actually i'm about to be finished from ASCII, UTF8 classes but now i'm stuck at print function.
Muhammad alaa
+1  A: 

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/

Sherwood Hu
so you mean that standard streams use current system locale? i think depending on what you said that my classes should detect what current code page the system use and depends on that it write the string data. what happend to stream data if encoding changed?
Muhammad alaa