本文整理汇总了C++中SetConsoleOutputCP函数的典型用法代码示例。如果您正苦于以下问题:C++ SetConsoleOutputCP函数的具体用法?C++ SetConsoleOutputCP怎么用?C++ SetConsoleOutputCP使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SetConsoleOutputCP函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: init_console
// 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
}
示例2: console_vprintf
/*
* 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);
}
示例3: GetConsoleOutputCP
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);
}
示例4: glfwGetTime
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);
}
示例5: _tmain
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;
}
示例6: setlocale
bool DaemonWin32::Start() {
setlocale(LC_CTYPE, "");
SetConsoleCP(1251);
SetConsoleOutputCP(1251);
setlocale(LC_ALL, "Russian"); // TODO(unassigned) set different locale
return Daemon_Singleton::Start();
}
示例7: hb_gt_cgi_Exit
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 );
}
}
示例8: main
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;
}
示例9: hb_gt_cgi_Init
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 );
}
示例10: setup_console
/**
* 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 */
}
}
}
示例11: _tmain
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;
}
示例12: php_win32_cp_cli_io_setup
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;
}/*}}}*/
示例13: setlocale
bool DaemonWin32::Start() {
setlocale(LC_CTYPE, "");
SetConsoleCP(65001);
SetConsoleOutputCP(65001);
setlocale(LC_ALL, "");
return Daemon_Singleton::Start();
}
示例14: main
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 ();
}
示例15: init_ti
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);
}