// Initialize the console, depending on the OS and language/code page settings void init_console() { #ifdef WIN32 #ifdef CH_USE_UNICODE SetConsoleOutputCP(65001); // use UTF-8 (Unicode) setlocale(LC_ALL,"English_United States.437"); // Windows does not support UTF-8/Unicode for setlocale, sorry #endif #ifdef CH_USE_CP437 SetConsoleOutputCP(437); // use Code Page 437 (US English code page made by IBM for DOS) setlocale(LC_ALL,"English_United States.437"); #endif #ifdef CH_USE_ASCII_HACK SetConsoleOutputCP(437); // use Code Page 437 (US English code page made by IBM for DOS) setlocale(LC_ALL,"English_United States.437"); #endif _setmbcp(_MB_CP_LOCALE); // use same code page as multibyte code page #else // WIN32 #ifdef CH_USE_UNICODE setlocale(LC_ALL,"en_US.UTF-8"); // POSIX-compliant OSes DO support UTF-8/Unicode for setlocale #endif #ifdef CH_USE_CP437 setlocale(LC_ALL,"en_US.CP437"); #endif #ifdef CH_USE_ASCII_HACK setlocale(LC_ALL,"en_US.CP437"); #endif #endif // WIN32 #ifdef CH_USE_UNICODE setup_unicode(); #endif }
/* * The console output format should be set to UTF-8, however in XP and Vista this breaks batch file processing. * Attempting to restore on exit fails to restore if the program is terminated by the user. * Solution - set the output format each printf. */ void console_vprintf(const char *fmt, va_list ap) { UINT cp = GetConsoleOutputCP(); SetConsoleOutputCP(CP_UTF8); vprintf(fmt, ap); SetConsoleOutputCP(cp); }
void FileTests::TestUtf8WriteFileInvalid() { Log::Comment(L"Backup original console codepage."); UINT const uiOriginalCP = GetConsoleOutputCP(); auto restoreOriginalCP = wil::scope_exit([&] { Log::Comment(L"Restore original console codepage."); SetConsoleOutputCP(uiOriginalCP); }); HANDLE const hOut = GetStdOutputHandle(); VERIFY_IS_NOT_NULL(hOut, L"Verify we have the standard output handle."); VERIFY_WIN32_BOOL_SUCCEEDED(SetConsoleOutputCP(CP_UTF8), L"Set output codepage to UTF8"); DWORD dwWritten; DWORD dwExpectedWritten; char* str; DWORD cbStr; // \x80 is an invalid UTF-8 continuation // \x40 is the @ symbol which is valid. str = "\x80\x40"; cbStr = (DWORD)strlen(str); dwWritten = 0; dwExpectedWritten = cbStr; VERIFY_WIN32_BOOL_SUCCEEDED(WriteFile(hOut, str, cbStr, &dwWritten, nullptr)); VERIFY_ARE_EQUAL(dwExpectedWritten, dwWritten); // \x80 is an invalid UTF-8 continuation // \x40 is the @ symbol which is valid. str = "\x80\x40\x40"; cbStr = (DWORD)strlen(str); dwWritten = 0; dwExpectedWritten = cbStr; VERIFY_WIN32_BOOL_SUCCEEDED(WriteFile(hOut, str, cbStr, &dwWritten, nullptr)); VERIFY_ARE_EQUAL(dwExpectedWritten, dwWritten); // \x80 is an invalid UTF-8 continuation // \x40 is the @ symbol which is valid. str = "\x80\x80\x80\x40"; cbStr = (DWORD)strlen(str); dwWritten = 0; dwExpectedWritten = cbStr; VERIFY_WIN32_BOOL_SUCCEEDED(WriteFile(hOut, str, cbStr, &dwWritten, nullptr)); VERIFY_ARE_EQUAL(dwExpectedWritten, dwWritten); }
void Application::Init() { double T1 = glfwGetTime(); ParseArgs(); #ifdef WIN32 SetConsoleOutputCP(CP_UTF8); _setmode(_fileno(stdout), _O_U8TEXT); #endif GameState::GetInstance().Initialize(); GameState::Printf("Initializing... \n"); Configuration::Initialize(); FileManager::Initialize(); if (RunMode == MODE_PLAY || RunMode == MODE_VSRGPREVIEW) { WindowFrame.AutoSetupWindow(this); InitAudio(); Game = NULL; } GameState::Printf("Total Initialization Time: %fs\n", glfwGetTime() - T1); }
int _tmain(int argc, _TCHAR* argv[]) { SetConsoleCP(1251); SetConsoleOutputCP(1251); setlocale(LC_ALL, "Rus"); Train *trains = nullptr; int count = 0; cout << "¬ведите количество поездов: "; cin >> count; trains = new Train[count]; cout << "=========================================================================\n"; for (int i = 0; i < count; ++i) { trains[i].Show(); cout << "=========================================================================\n"; } Train *maxTrain = GetMaxTrain(trains, count); cout << "Ќаибольшее количество пассажиров в поезде номер " << maxTrain->GetTrainNumber() << endl; cout << " оличество пассажиров: " << maxTrain->GetPassengersCount() << endl; Train *minTrain = GetMinTrain(trains, count); cout << "Ќаименьшее количество пассажиров в поезде номер " << minTrain->GetTrainNumber() << endl; cout << " оличество пассажиров: " << minTrain->GetPassengersCount() << endl; delete[] trains; system("pause"); return 0; }
bool DaemonWin32::Start() { setlocale(LC_CTYPE, ""); SetConsoleCP(1251); SetConsoleOutputCP(1251); setlocale(LC_ALL, "Russian"); // TODO(unassigned) set different locale return Daemon_Singleton::Start(); }
static void hb_gt_cgi_Exit( PHB_GT pGT ) { PHB_GTCGI pGTCGI; HB_TRACE( HB_TR_DEBUG, ( "hb_gt_cgi_Exit(%p)", pGT ) ); HB_GTSELF_REFRESH( pGT ); pGTCGI = HB_GTCGI_GET( pGT ); HB_GTSUPER_EXIT( pGT ); if( pGTCGI ) { #if defined( HB_OS_WIN ) && ! defined( HB_OS_WIN_CE ) if( IsValidCodePage( CP_UTF8 ) ) SetConsoleOutputCP( pGTCGI->uiOldCP ); #endif /* update cursor position on exit */ if( pGTCGI->iLastCol > 0 ) hb_gt_cgi_newLine( pGTCGI ); #ifndef HB_GT_CGI_RAWOUTPUT if( pGTCGI->iLineBufSize > 0 ) hb_xfree( pGTCGI->sLineBuf ); #endif if( pGTCGI->szCrLf ) hb_xfree( pGTCGI->szCrLf ); hb_xfree( pGTCGI ); } }
int main(int argc, char *argv[]) { setlocale(LC_ALL, "Russian"); SetConsoleOutputCP(1251); SetConsoleCP(1251); if (argc == 1) { std::map <std::string, size_t> wordsStore; std::string inputString; while (std::getline(std::cin, inputString)) { wordsStore.clear(); if (inputString.empty()) { break; } wordsStore = FindAndCountWordsFromString(inputString); for (auto &it : wordsStore) { std::cout << it.first << " -> " << it.second << std::endl; } } } return 0; }
static void hb_gt_cgi_Init( PHB_GT pGT, HB_FHANDLE hFilenoStdin, HB_FHANDLE hFilenoStdout, HB_FHANDLE hFilenoStderr ) { PHB_GTCGI pGTCGI; HB_TRACE( HB_TR_DEBUG, ( "hb_gt_cgi_Init(%p,%p,%p,%p)", pGT, ( void * ) ( HB_PTRDIFF ) hFilenoStdin, ( void * ) ( HB_PTRDIFF ) hFilenoStdout, ( void * ) ( HB_PTRDIFF ) hFilenoStderr ) ); pGTCGI = ( PHB_GTCGI ) hb_xgrab( sizeof( HB_GTCGI ) ); memset( pGTCGI, 0, sizeof( HB_GTCGI ) ); HB_GTLOCAL( pGT ) = pGTCGI; pGTCGI->hStdout = hFilenoStdout; #if defined( HB_OS_WIN ) && ! defined( HB_OS_WIN_CE ) if( IsValidCodePage( CP_UTF8 ) ) { pGTCGI->uiOldCP = GetConsoleOutputCP(); SetConsoleOutputCP( CP_UTF8 ); HB_GTSELF_SETDISPCP( pGT, "UTF8", NULL, HB_FALSE ); } #endif pGTCGI->szCrLf = hb_strdup( hb_conNewLine() ); pGTCGI->nCrLf = strlen( pGTCGI->szCrLf ); hb_fsSetDevMode( pGTCGI->hStdout, FD_BINARY ); HB_GTSUPER_INIT( pGT, hFilenoStdin, hFilenoStdout, hFilenoStderr ); HB_GTSELF_SETFLAG( pGT, HB_GTI_STDOUTCON, HB_TRUE ); }
/** * Prepare console on program initialization: change console font codepage * according to program options and hide cursor. */ void setup_console(void) { HANDLE hOut; CONSOLE_CURSOR_INFO cci; int cp = (opt.flags&OPT_UTF8 ? CP_UTF8 : opt.flags&OPT_ANSI ? GetACP() : GetOEMCP()); rhash_data.saved_console_codepage = -1; /* note: we are using numbers 1 = _fileno(stdout), 2 = _fileno(stderr) */ /* cause _fileno() is undefined, when compiling as strict ansi C. */ if(cp > 0 && IsValidCodePage(cp) && (isatty(1) || isatty(2)) ) { rhash_data.saved_console_codepage = GetConsoleOutputCP(); SetConsoleOutputCP(cp); setlocale(LC_CTYPE, opt.flags&OPT_UTF8 ? "C" : opt.flags&OPT_ANSI ? ".ACP" : ".OCP"); rsh_exit = rhash_exit; } if((opt.flags & OPT_PERCENTS) != 0) { hOut = GetStdHandle(STD_ERROR_HANDLE); if(hOut != INVALID_HANDLE_VALUE) { /* store current cursor size and visibility flag */ GetConsoleCursorInfo(hOut, &cci); rhash_data.saved_cursor_size = (cci.bVisible ? cci.dwSize : 0); /* now hide cursor */ cci.bVisible = 0; SetConsoleCursorInfo(hOut, &cci); /* hide cursor */ } } }
int _tmain(int argc, _TCHAR* argv[]) { LoadLibrary(_T("testecdll.dll")); if (argc < 2) { Display("testec <depth> [<multiply>]\n"); return -1; } depth = _ttoi(argv[1]); // Display("%2d", depth); SetConsoleOutputCP(CP_OEMCP); Display("%d(%d) Depth: %d Starting stdin=%d stdout=%d stderr=%d\n", GetCurrentProcessId(), GetCurrentThreadId(), depth, GetStdHandle(STD_INPUT_HANDLE), GetStdHandle(STD_OUTPUT_HANDLE), GetStdHandle(STD_ERROR_HANDLE)); int rc = -1; try { //__try { // __try { rc = _tmain1(argc, argv); // } __except(EXCEPTION_EXECUTE_HANDLER) // { // Display("EXCEPTION: %d\n", GetExceptionCode()); // DebugBreak(); // } //} __finally { // if (rc != 1) { // DebugBreak(); // } //} } catch(...) { DebugBreak(); } Display("%d(%d) Exiting and closing stdin=%d stdout=%d stderr=%d\n", GetCurrentProcessId(), GetCurrentThreadId(), GetStdHandle(STD_INPUT_HANDLE), GetStdHandle(STD_OUTPUT_HANDLE), GetStdHandle(STD_ERROR_HANDLE)); return rc; }
static BOOL php_win32_cp_cli_io_setup(void) {/*{{{*/ BOOL ret = TRUE; if (PG(input_encoding) && PG(input_encoding)[0]) { cur_in_cp = php_win32_cp_get_by_enc(PG(input_encoding)); if (!cur_in_cp) { cur_in_cp = cur_cp; } } else { cur_in_cp = cur_cp; } if (PG(output_encoding) && PG(output_encoding)[0]) { cur_out_cp = php_win32_cp_get_by_enc(PG(output_encoding)); if (!cur_out_cp) { cur_out_cp = cur_cp; } } else { cur_out_cp = cur_cp; } if(php_get_module_initialized()) { ret = SetConsoleCP(cur_in_cp->id) && SetConsoleOutputCP(cur_out_cp->id); } return ret; }/*}}}*/
bool DaemonWin32::Start() { setlocale(LC_CTYPE, ""); SetConsoleCP(65001); SetConsoleOutputCP(65001); setlocale(LC_ALL, ""); return Daemon_Singleton::Start(); }
void main(int argc, char* argv[]) { Core._initialize("mp_ballancer", NULL, TRUE, "fsgame4mpu.ltx"); SetConsoleOutputCP(1251); weapon_collection wpn_collection; wpn_collection.load_all_mp_weapons(); if (argc == 2) { if (!strcmp(argv[1], "export_configs")) { wpn_collection.extract_all_params (); wpn_collection.save_new_configs (); } else if (!strcmp(argv[1], "made_csv")) { statistics_collector stat_collector(&wpn_collection); stat_collector.load_settings(); stat_collector.save_files(); } } Core._destroy (); }
static void init_ti(void) { CONSOLE_SCREEN_BUFFER_INFO info; int i; UINT acp; if (ti_flag) return; ti_flag = 1; for (i = 0; i<2; ++i) { if (GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &info)) break; if (i) return; FreeConsole(); AllocConsole(); } ti.normattr = info.wAttributes; ti.winright = info.dwSize.X; ti.winbottom = info.dwSize.Y; ti.screenwidth = info.dwSize.X; ti.screenheight = info.dwSize.Y; ti.curx = info.dwCursorPosition.X + 1; ti.cury = info.dwCursorPosition.Y + 1; ti.attribute = info.wAttributes; acp = GetACP(); if (GetConsoleOutputCP() != acp) { SetConsoleOutputCP(acp); SetConsoleCP(acp); } SetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), ENABLE_WINDOW_INPUT | ENABLE_MOUSE_INPUT | ENABLE_ECHO_INPUT); }
void kull_m_output_init() { previousStdOut = _setmode(_fileno(stdout), _O_U8TEXT); previousStdErr = _setmode(_fileno(stderr), _O_U8TEXT); previousConsoleOutput = GetConsoleOutputCP(); SetConsoleOutputCP(CP_UTF8); }
//Установка русской локали inline void SetLoc(UINT loc) { //setlocale( LC_ALL, "ru_RU.cp1251" ); //Русская локаль SetConsoleCP(loc); SetConsoleOutputCP(loc); }
int main () { SetConsoleOutputCP(1251); SetConsoleCP(1251); const char dumpFilename[] = "dump"; const char saveFilename[] = "save"; // Node_t * nd = newNode ("aha", newNode ("столовка", NULL, newNode ("ops", NULL, NULL)), NULL); Node_t * nd = TreeLoad (saveFilename); QUIZ (nd); // TreePrint (nd, stdout); TreeDump (nd, dumpFilename); FILE * out = fopen (saveFilename, "w"); assert (out); TreePrint (nd, out); fclose (out); TreeDel (&nd); return 0; }
int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { UNREFERENCED_PARAMETER(hPrevInstance); UNREFERENCED_PARAMETER(lpCmdLine); #ifdef USE_WIN32_CONSOLE AllocConsole(); SetConsoleCP(CP_ACP); SetConsoleOutputCP(CP_ACP); freopen("CONIN$", "r", stdin); freopen("CONOUT$", "w", stdout); freopen("CONOUT$", "w", stderr); #endif // create the application instance AppDelegate app; int nRet = Application::getInstance()->run(); //app.applicationWillTerminate(); #ifdef USE_WIN32_CONSOLE FreeConsole(); #endif ::Sleep(500); #if CC_REF_LEAK_DETECTION > 0 Ref::printLeaks(); #endif return nRet; }
void Create_FiLe() { setlocale(LC_ALL,"Russian"); SetConsoleCP(1251); SetConsoleOutputCP(1251); ofstream vlad1("vlad1.txt"); int n; cout<<"Введiть кiлькiсть символiв n="; cin>>n; char *a=new char[n]; cout<<"Введiть рядок :\n"; for(int i=0;i<n;i++) cin>>a[i]; vlad1<<"Усi символи: \n"; for(int i=0;i<n;i++) {vlad1<<a[i];} vlad1<<"\n"; vlad1<<"Кирилиця: \n"; for(int i=0;i<n;i++) {for(int j=i+1;j<n;j++) {if (a[i]==a[j]) { a[i]=-5; }}} ofstream fail1("Max-vidsortovanuy.txt"); for(int i=0;i<n;i++) {if (a[i]==-5) continue; vlad1<<a[i]<<" "; } vlad1.close(); }
int main() { SetConsoleOutputCP(1251); A.x = 65; B.x = 90; cout << "Тип элементов:\n 1 - int\n 2 - double\n 3 - char\n"; cin >> x; if( x < 1 || x > 3 ) { cout << "Указано неверное значение типа элемента."; _getch(); return 0; } cout << "Количество элементов: "; cin >> N; if( N < 1 ) { cout << "Количеcтво элементов не может быть отрицательным!Попробуйте еще раз."; _getch(); return 0; } if( x != 3 ) { cout << "Промежуток (a,b): "; if( x == 2 ) { cin >> A.y >> B.y; }
void WindowManager::setup() { //Set console font CONSOLE_FONT_INFOEX lpConsoleCurrentFontEx; lpConsoleCurrentFontEx.cbSize = sizeof(CONSOLE_FONT_INFOEX); lpConsoleCurrentFontEx.dwFontSize.X = 12; lpConsoleCurrentFontEx.dwFontSize.Y = 12; lpConsoleCurrentFontEx.FontWeight = 700; lpConsoleCurrentFontEx.nFont = 1; lpConsoleCurrentFontEx.FontFamily = FF_DONTCARE; lstrcpyW(lpConsoleCurrentFontEx.FaceName, L"Lucida Console"); SetCurrentConsoleFontEx ( GetStdHandle(STD_OUTPUT_HANDLE), false, &lpConsoleCurrentFontEx ); //get handles and create screen buffers mStdHandle = GetStdHandle(STD_OUTPUT_HANDLE); mConsoleA = Console::createConsoleOutput(); mConsoleB = Console::createConsoleOutput(); mSwitch = true; CONSOLE_SCREEN_BUFFER_INFO info; if (GetConsoleScreenBufferInfo(mStdHandle, &info) != 0) { mCurrentSize.X = (info.srWindow.Right - info.srWindow.Left) + 1; mCurrentSize.Y = (info.srWindow.Bottom - info.srWindow.Top) + 1; } else { mCurrentSize.X = 80; mCurrentSize.Y = 25; } //get current codepage and set new one, unicode mOldCodePage = GetConsoleOutputCP(); SetConsoleOutputCP(CP_UTF8); }
//Issue 60: BUGBUG: На некоторых системых (Win2k3, WinXP) SetConsoleCP (и иже с ними) просто зависают //Поэтому выполняем в отдельном потоке, и если он завис - просто зовем TerminateThread static DWORD WINAPI OurSetConsoleCPThread(LPVOID lpParameter) { UINT nCP = (UINT)lpParameter; SetConsoleCP(nCP); SetConsoleOutputCP(nCP); return 0; }
/* Print some "press enter" message, wait for that, exit. */ static void doExit(int code) { /* set console codepage to OEM in case the process changed it to something else */ SetConsoleOutputCP(GetOEMCP()); puts(sleepMsg); _getch(); exit(code); }
// setlocale(LC_CTYPE,"Czech_Czech Republic.852"); bool console_mode(int mode) { static int defaultCP = 0; if(!defaultCP) defaultCP = GetConsoleOutputCP(); switch(mode) { case CONSOLE_IO: if(!setlocale(LC_CTYPE,"C")) return false; if(!SetConsoleCP(defaultCP)) return false; if(!SetConsoleOutputCP(defaultCP)) return false; break; case CONSOLE_UTF: if(!setlocale(LC_CTYPE,"C")) return false; if(!SetConsoleCP(65001)) return false; if(!SetConsoleOutputCP(65001)) return false; break; }; return true; }
Console::~Console() { // Reset Windows console to old code page // We need to stick with the unicode font since // changing back will destroy the console history if (m_shouldResetCodePage) { SetConsoleOutputCP(m_oldCodePage); } }
/** * @brief CON_Init */ void CON_Init(void) { CONSOLE_CURSOR_INFO curs; CONSOLE_SCREEN_BUFFER_INFO info; int i; // handle Ctrl-C or other console termination SetConsoleCtrlHandler(CON_CtrlHandler, TRUE); qconsole_hin = GetStdHandle(STD_INPUT_HANDLE); if (qconsole_hin == INVALID_HANDLE_VALUE) { return; } qconsole_hout = GetStdHandle(STD_OUTPUT_HANDLE); if (qconsole_hout == INVALID_HANDLE_VALUE) { return; } GetConsoleMode(qconsole_hin, &qconsole_orig_mode); // allow mouse wheel scrolling SetConsoleMode(qconsole_hin, qconsole_orig_mode & ~ENABLE_MOUSE_INPUT); FlushConsoleInputBuffer(qconsole_hin); GetConsoleScreenBufferInfo(qconsole_hout, &info); qconsole_attrib = info.wAttributes; #ifdef DEDICATED SetConsoleTitle(ET_VERSION " Dedicated Server Console"); #else SetConsoleTitle(ET_VERSION " Client Console"); #endif // make cursor invisible GetConsoleCursorInfo(qconsole_hout, &qconsole_orig_cursorinfo); curs.dwSize = 1; curs.bVisible = FALSE; SetConsoleCursorInfo(qconsole_hout, &curs); qconsole_backgroundAttrib = qconsole_attrib & (BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED | BACKGROUND_INTENSITY); // initialize history for (i = 0; i < QCONSOLE_HISTORY; i++) { qconsole_history[i][0] = '\0'; } // set text color to white SetConsoleTextAttribute(qconsole_hout, CON_ColorCharToAttrib(COLOR_WHITE)); // set process output translation SetConsoleOutputCP(CP_UTF8); }
bool DaemonWin32::start() { setlocale(LC_CTYPE, ""); SetConsoleCP(1251); SetConsoleOutputCP(1251); setlocale(LC_ALL, "Russian"); return Daemon_Singleton::start(); }
CAMLprim value win_set_console_output_cp (value cp) { BOOL res; res = SetConsoleOutputCP (Int_val (cp)); if (res == 0) { win32_maperr (GetLastError ()); uerror("set_console_cp", Nothing); } return (Val_unit); }
void kull_m_output_clean() { #ifndef _POWERKATZ #ifndef _WINDLL _setmode(_fileno(stdout), previousStdOut); _setmode(_fileno(stderr), previousStdErr); #endif SetConsoleOutputCP(previousConsoleOutput); #endif }