System windows server 2008 rc2

Challenges

setlocale(LC_ALL,"Rus"); setlocale( LC_ALL, "ru_RU.CP1251" ); std::system("chcp 1251"); не прокатывают 

The GetACP () function (from winnls.h) returns 1252, but should 1251.

If you manually change the system language Control Panel - Clock, language and region - the language and regional standards - in addition - the language of programs that do not support Unicode.

In Russian, GetACP () returns 1251.

  1. Is it possible to do this?
  2. Is it possible to do this without connecting non-standard libraries?
  • Good question. I have in Windows 7 in general - after installation it is Russian. So in order to make it work, you must first change it according to the procedure you specified (changed to US), and then again change to Russian. At first (when I put the seven for the first time) I thought that I was just “naughty” somewhere, but with the following installations I had to do the same. Interestingly, everyone has it? - avp
  • That is, it turns out how. Launching let's say Turkish windows with Turkish locale. std :: string file_name = "file.txt"; The compiled code looks like this: std :: string file_name = 80 42 18 96 121 45 67; // character codes std :: wstring file_name = 1801 1423; // unicode Further, in accordance with the settings of the locale, fstream accepting the file_name informs the system that the encoding is Turkish. And on the disk file in Russian. And since it works in unix, it means there are probably some difficulties in windows? And setlocale in theory should be correctly executed? Hence it turns out that there is no way to fix it? - manking

1 answer 1

Changing Non-Unicode programmatically to Russian .

You need the NtSetDefaultLocale . From the user-accessible interface of the Windows libraries, SetLocaleInfo is most suitable, but according to the description it will be too weak for your task = (

PS Found! Try SystemParametersInfo with SPI_SETDEFAULTINPUTLANG . I never would have guessed !!!

  • Those. I correctly understand that the desired behavior, so that FOR YOUR program, the GetACP() call returns 1251, regardless of the system settings? - gecube
  • Regarding the reboot, no, not necessarily. A special message [WM_SETTINGCHANGE] [1] is sent to all windows. So in theory, settings can change without rebooting. [1]: msdn.microsoft.com/en-us/library/windows/desktop/ms725497.aspx - gecube
  • Eeeeee. I have another question. And why do you GetACP() to change the value returned by GetACP() ? The problem is in fact in those functions that require the assignment of a code page. What prevents them from asking what you need? Can you give examples of such functions used in your program? - gecube
  • Well, here is the simplest example. The file "file.txt" will be opened only if the system language is Russian. #include <fstream> #include <string> int main () {std :: system ("chcp 1251"); std :: string file_name = "file.txt"; std :: fstream file_read (file_name, std :: ios :: in | std :: ios :: binary); if (! file_read) {std :: cout << "\ nerror =" << file_read; } std :: cout << "\ nfile open =" << file_name; } - manking pm
  • one
    As for the standard C ++ standard library with respect to encodings, this is a bit wrong. I do not know, as in Windows, but in the line a combination of setting the necessary locales with std :: setlocale and std :: locale :: global + wstring, wcout, wfstream, etc. solve the problem without problems. In addition, you can set your locale for each file stream using the imbue method - skegg