GetConsoleOutputCP SetConsoleOutputCP

http://www.cplusplus.com/forum/windows/9797/


After a bit of googling I came across the following:

http://msdn.microsoft.com/en-us/library/ms686036(VS.85).aspx -- SetConsoleOutputCP
http://msdn.microsoft.com/en-us/library/dd317756(VS.85).aspx -- code page ids
http://msdn.microsoft.com/en-us/library/ms683169(VS.85).aspx -- GetConsoleOutputCP

I suppose the way to do this would be:

1
2
3
4
5
6
7
8
9
10
11
12
13
int main()
{
  UINT oldcodepage = GetConsoleOutputCP();
  SetConsoleOutputCP(65001);  // for UTF-8 ... or use ?1251? for cyrillic
    // -- there appear to
    // be many different cyrillic options -- not sure which one is desired.
    // UTF-8, at least, is always consistent

  // ... output crap here

  SetConsoleOutputCP(oldcodepage);
  return 0;
}


UTF-8 is probably more easily portable, but then you have to make sure your text is UTF-8 encoded (and since cyrillic characters are multi-byte in UTF-8... things like std::string::length() and strlen() will return values higher than the actual number of characters).

Apparently you might also need to worry about SetConsoleCP, too for the input -- so you might have to look that up as well.

blech. Hope that works for you.

你可能感兴趣的:(String,input,UP,output)