void CreateConsoleWindow(int numLines, int numColumns, int windowLines, int windowColumns) { CONSOLE_SCREEN_BUFFER_INFO coninfo; // Get the console and set the number of lines AllocConsole(); GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &coninfo); coninfo.dwSize.Y = numLines; coninfo.dwSize.X = numColumns; SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE), coninfo.dwSize); SMALL_RECT rect; rect.Left = 0; rect.Top = 0; rect.Right = windowColumns; rect.Bottom = windowLines; SetConsoleWindowInfo(GetStdHandle(STD_OUTPUT_HANDLE), TRUE, &rect); FILE *stream; freopen_s(&stream, "CONIN$", "r", stdin); freopen_s(&stream, "CONOUT$", "w", stdout); freopen_s(&stream, "CONOUT$", "w", stderr); // Prevent accidental console window close HWND hwnd = GetConsoleWindow(); HMENU hmenu = GetSystemMenu(hwnd, FALSE); EnableMenuItem(hmenu, SC_CLOSE, MF_GRAYED); }
void Console::RedirectStandardIO() { FILE *in, *out, *err; freopen_s(&in, "CONIN$", "rb", stdin); // reopen stdin handle as console window input freopen_s(&out, "CONOUT$", "wb", stdout); // reopen stout handle as console window output freopen_s(&err, "CONOUT$", "wb", stderr); // reopen stderr handle as console window output }
VOID MakeConsole(VOID) { DWORD dwMode; struct _CONSOLE_SCREEN_BUFFER_INFO sbi; HANDLE hStd; FILE *fStream; //if (!InitializeCriticalSectionAndSpinCount(&CriticalSection, 0x00000400)) { // DbgMsg("[-] InitializeCriticalSectionAndSpinCount failed : %lu\n", GetLastError()); //} //InitializeCriticalSection(&CriticalSection); InitCriticalSection(); if (!AllocConsole()) { FreeConsole(); if (!AllocConsole()) { DbgMsg("[+] AllocConsole() failed : %lu\n", GetLastError()); } } hStd = GetStdHandle(STD_OUTPUT_HANDLE); GetConsoleMode(hStd, (LPDWORD)&dwMode); SetConsoleMode(hStd, dwMode & 0xFFFFFFEF); GetConsoleScreenBufferInfo(hStd, &sbi); sbi.dwSize.Y = 500; SetConsoleScreenBufferSize(hStd, sbi.dwSize); freopen_s(&fStream, "conin$", "r", stdin); freopen_s(&fStream, "conout$", "w", stdout); freopen_s(&fStream, "conout$", "w", stderr); }
int main() { FILE *f; freopen_s(&f, "input.txt", "r", stdin); freopen_s(&f, "output.txt", "w", stdout); int N, temp; int *arr; int i, j; scanf_s("%d", &N); arr = (int *)malloc(sizeof(int)*N); for (i = 0; i < N; i++) { scanf_s("%d", &arr[i]); } for (i = 0; i < N - 1; i++) { for (j = 0; j < N - i; j++) if (arr[j - 1] > arr[j]) { temp = arr[j - 1]; arr[j - 1] = arr[j]; arr[j] = temp; } } for (i = 0; i < N; i++) printf("%d ", arr[i]); return 0; }
int main() { FILE *f; freopen_s(&f, "input.txt", "r", stdin); freopen_s(&f, "output.txt", "w", stdout); int n, sum = 0, min = 999, flag = 0; for (int i = 0; i < 7; i++) { scanf_s("%d", &n); if (n % 2 == 1) { sum += n; if (min >= n) min = n; flag = 1; } } if (flag == 0) printf("-1"); else printf("%d %d", sum, min); return 0; }
BOOL SysConsole::Open( int x, int y, int w, int h ) { BOOL r = AllocConsole(); if (!r) return r; AttachConsole(GetCurrentProcessId()); MoveWindow(GetConsoleWindow(), x, y, w, h, true); m_cinbuf = std::cin.rdbuf(); m_console_cin.open("CONIN$"); std::cin.rdbuf(m_console_cin.rdbuf()); m_coutbuf = std::cout.rdbuf(); m_console_cout.open("CONOUT$"); std::cout.rdbuf(m_console_cout.rdbuf()); m_cerrbuf = std::cerr.rdbuf(); m_console_cerr.open("CONOUT$"); std::cerr.rdbuf(m_console_cerr.rdbuf()); FILE *stream; freopen_s(&stream, "conin$", "r", stdin); freopen_s(&stream, "conout$", "w", stdout); freopen_s(&stream, "conout$", "w", stdout); return r; }
void Win32AllocateStdioConsole(const char * optArg) { const String optOutFile = optArg; const char * conInStr = optOutFile.HasChars() ? NULL : "conin$"; const char * conOutStr = optOutFile.HasChars() ? optOutFile() : "conout$"; if (optOutFile.IsEmpty()) AllocConsole(); // no sense creating a DOS window if we're only outputting to a file anyway // Hopefully-temporary work-around for Windows not wanting to send stdout and stderr to the same file String conErrHolder; // don't move this! It needs to stay here const char * conErrStr = NULL; if (optOutFile.HasChars()) { const int lastDotIdx = optOutFile.LastIndexOf('.'); if (lastDotIdx > 0) conErrHolder = optOutFile.Substring(0, lastDotIdx) + "_stderr" + optOutFile.Substring(lastDotIdx); else conErrHolder = optOutFile + "_stderr.txt"; conErrStr = conErrHolder(); } else conErrStr = conOutStr; // for the output-to-console-window case, where redirecting both stdout and stderr DOES work # if __STDC_WANT_SECURE_LIB__ FILE * junk; if (conInStr) (void) freopen_s(&junk, conInStr, "r", stdin); if (conOutStr) (void) freopen_s(&junk, conOutStr, "w", stdout); if (conErrStr) (void) freopen_s(&junk, conErrStr, "w", stderr); # else if (conInStr) (void) freopen(conInStr, "r", stdin); if (conOutStr) (void) freopen(conOutStr, "w", stdout); if (conErrStr) (void) freopen(conErrStr, "w", stderr); # endif }
/** * @function OnInit * @brief Initialize GRIP window * @date 2011-10-13 */ bool GRIPApp::OnInit() { #ifdef WIN32 // --- Console --- FILE* pFile; AllocConsole(); SetConsoleTitle(L"GRIP Console"); freopen_s( &pFile, "conin$", "r", stdin ); freopen_s( &pFile, "conout$", "w", stdout ); freopen_s( &pFile, "conout$", "w", stderr ); #endif // --- Console --- if ( !wxApp::OnInit() ) return false; frame = new GRIPFrame(wxT("GRIP")); frame->SetFocus(); AddTabs(); wxInitAllImageHandlers(); wxImage gripimg = wxImage(robot_xpm); char r,g,b; gripimg.InitAlpha(); for(int i=0; i<16; i++)for(int j=0; j<16; j++){ r=gripimg.GetRed(i,j);g=gripimg.GetBlue(i,j);b=gripimg.GetGreen(i,j); if(r == g && g == b) gripimg.SetAlpha(i,j,255-r); } wxIcon ico; ico.CopyFromBitmap(wxBitmap(gripimg)); frame->SetIcon(ico); frame->Show(true); return true; }
LRESULT CALLBACK SystemClass::MessageHandler(HWND hwnd, UINT umsg, WPARAM wparam, LPARAM lparam) { switch (umsg) { case WM_CREATE: AllocConsole(); FILE *acStreamOut; FILE *acStreamIn; freopen_s(&acStreamOut, "CONOUT$", "wt", stdout); freopen_s(&acStreamIn, "CONIN$", "r", stdin); // Check if a key has been pressed on the keyboard. case WM_KEYDOWN: // If a key is pressed send it to the input object so it can record that state. InputClass::GetInstance()->KeyDown((unsigned int)wparam); return 0; // Check if a key has been released on the keyboard. case WM_KEYUP: // If a key is released then send it to the input object so it can unset the state for that key. InputClass::GetInstance()->KeyUp((unsigned int)wparam); return 0; // Any other messages send to the default message handler as our application won't make use of them. default: return DefWindowProc(hwnd, umsg, wparam, lparam); } }
scCore::scCore(string const& cfgFilePath, bool useConsole/*= false*/) : mUseConsole(useConsole), mRenderer(0), mGameWorldManager(0), mTimeLineManager(0), mEventRouter(0) { if (mUseConsole) { // 创建控制台窗口,并将标准输入流,标准输出流和标准错误流重定向至控制台 if( !AllocConsole() ) MessageBoxA(NULL, "控制台生成失败。", NULL, 0); SetConsoleTitleA("Debug Window"); freopen_s(&fpDebugOut, "CONOUT$","w", stdout); freopen_s(&fpDebugIn, "CONIN$", "r", stdin); freopen_s(&fpDebugErr, "CONOUT$","w", stderr); setlocale(LC_ALL, "chs"); std::cout << "控制台已创建!" << std::endl; } // 初始化渲染子系统 mRenderer = new scRenderer("resources_d.cfg", "plugins_d.cfg"); // 初始化输入子系统 u32 windowHnd = 0; mRenderer->getOgreRoot()->getAutoCreatedWindow()->getCustomAttribute("WINDOW", &windowHnd); u32 winWidth, winHeight, colDepth; i32 winLeft, winTop; mRenderer->getOgreRoot()->getAutoCreatedWindow()->getMetrics(winWidth, winHeight, colDepth, winLeft, winTop); mInputManager = new scInputManager(windowHnd, winWidth, winHeight); // 初始化事件路由器 mEventRouter = new scEventRouter(); // 初始化游戏世界管理类 mGameWorldManager = new scGameWorldManager(); // 初始化动画管理类 mAnimationManager = new scAnimationManager(); // 创建时间轴管理类 mTimeLineManager = new scTimeLineManager(); // 创建渲染和输入时间轴,60hz scTimeLinePtr tl = mTimeLineManager->createTimeLine("Render", 60); tl->addRunCallBack("Render", [&](u32 dtms)->bool{return mRenderer->_run(dtms);}); tl->addRunCallBack("Input", [&](u32 dtms)->bool{mInputManager->_run(); return true;}); // 创建动画时间轴,60hz tl = mTimeLineManager->createAnimationTimeLine("Animation", 60); // 创建事件路由时间轴, 无时间间隔(新线程) tl = mTimeLineManager->createTimeLine("Event", 1000, 0, true); tl->addRunCallBack("Event", [&](u32 dtms)->bool{mEventRouter->_run(); return true;}); // 创建游戏世界时间轴, 60Hz tl = mTimeLineManager->createTimeLine("GameWorld", 60); tl->addRunCallBack("GameWorld", [&](u32 dtms)->bool{return mGameWorldManager->_run(dtms);}); // 创建背景加载时间轴,10Hz(新线程) //tl = mTimeLineManager->createTimeLine("BackgroundLoading", 10, 0, true); // 测试一下 scGameWorldPtr gw(new scGameWorld("test", "testini.lua", "iniScene")); mGameWorldManager->addGameWorld(gw->getName(), gw); mGameWorldManager->initializeGameWorld("test"); }
void CUtil::FAllocConsole() { AllocConsole(); FILE* f1; FILE* f2; FILE* f3; freopen_s(&f1, "CONOUT$", "wb", stdout); freopen_s(&f2, "CONOUT$", "wb", stderr); freopen_s(&f3, "CONIN$", "rb", stdin); }
void Console::Initialize() { // Create console window FreeConsole(); AllocConsole(); // Redirect streams to the newly created console FILE* console = nullptr; freopen_s(&console, "CONIN$", "r", stdin); freopen_s(&console, "CONOUT$", "w", stdout); freopen_s(&console, "CONOUT$", "w", stderr); }
// Create console screen buffer and set it to application bool CTeslaDecrypterApp::SetConsoleBuffers() { FILE * fOut = NULL, *fIn = NULL, *fErr = NULL; freopen_s(&fOut, "CON", "w", stdout ) ; freopen_s(&fIn, "CON", "r", stdin ) ; freopen_s(&fErr, "CON", "w", stderr ) ; std::cin.clear(); std::cout.clear(); std::cerr.clear(); std::ios::sync_with_stdio(); rewind(stdout); rewind(stdin); return (fOut != NULL); }
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { //コンソール画面の呼び出し AllocConsole(); FILE* fp; freopen_s(&fp, "CONOUT$", "w", stdout); freopen_s(&fp, "CONIN$", "r", stdin); Application app(hInstance, hPrevInstance, lpCmdLine, nCmdShow); if (!app.Run())return 1; FreeConsole();//コンソールの解放 return 0; }
int StartUp() { AllocConsole(); AttachConsole(GetCurrentProcessId()); FILE* fp = NULL; freopen_s(&fp, "CON", "w", stdout); freopen_s(&fp, "CON", "w", stderr); char cc[128]; sprintf_s(cc,"Server: %i",GetCurrentProcessId()); SetConsoleTitleA(cc); return 1; }
int main(int argc, char** argv) #endif { Logger::getInstance().log(INFO_LOG_NAME, "Application started. Hello, World!"); Logger::getInstance().log(INFO_LOG_NAME, CString("Application version: ") + Version + " " + CString(BUILD_STR)); #if defined(WIN32) && defined(DEBUG) AllocConsole(); FILE* stream = NULL; errno_t err = freopen_s(&stream, "CON", "w", stdout); #endif BoxCar& game = BoxCar::getInstance(); bool res = game.init(); if (res) { Logger::getInstance().log(INFO_LOG_NAME, "Initialization successfully completed"); game.run(); } else { Logger::getInstance().log(ERROR_LOG_NAME, "Something went horribly wrong. Look above for details."); } #if defined(WIN32) && defined(DEBUG) FreeConsole(); #endif Logger::getInstance().log(INFO_LOG_NAME, "Application ended. Bye!"); }
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { int exitcode = 0; //Allocate a console window //so that messages can be redirected to stdout if (!AllocConsole()) { ErrorExit(TEXT("AllocConsole")); } FILE* pf_out; freopen_s(&pf_out, "CONOUT$", "w", stdout); PrintUsage(); //Create the application instance OGLApplication* myapp = OGLApplication::CreateApplication(hInstance); exitcode = myapp->Run(); myapp->DestroyApplication(); fclose(pf_out); //Free the console window if (!FreeConsole()) { ErrorExit(TEXT("FreeConsole")); } return exitcode; }
void init() { freopen_s(&output, "output.txt", "w", stdout); int n = 0; scanf_s("%d", &n); len = n; }
int main() { FILE *f; freopen_s(&f, "input.txt", "r", stdin); char ch; int i; fseek(f, 2, SEEK_SET); scanf_s("%c", &ch); freopen_s(&f, "output.txt", "w", stdout); printf("%c %d", ch,ch); return 0; }
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdParam, int nShowCmd ){ #ifdef _DEBUG _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF|_CRTDBG_LEAK_CHECK_DF); //_CrtSetBreakAlloc( ); AllocConsole(); FILE* console; freopen_s( &console, "CONOUT$", "wt", stdout ); printf_s("Console Open \n"); #endif NNApplication* Application = NNApplication::GetInstance(); Application->Init( L"Amutena Pizza", 1024, 640, D2D ); NNSceneDirector::GetInstance()->ChangeScene( CMainTitleScene::Create()); Application->Run(); Application->Release(); #ifdef _DEBUG FreeConsole(); #endif return 0; }
void iexSystem::OpenDebugWindow() { #ifdef _DEBUG AllocConsole(); freopen_s( &DebugFP, "CON", "w", stdout); #endif }
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR pScmdline, int iCmdshow) { #ifdef _DEBUG FILE *stream; //debug下需要一个控制台输出调试信息 AllocConsole(); freopen_s(&stream, "CONOUT$", "w", stdout); #endif DrawFunction my_d3d_haha; my_d3d_haha.WinMain_InitWindow(hInstance, iCmdshow); if (FALSE == my_d3d_haha.Init()) return FALSE; else printf("This is the template_3 for my DirectX_11 project \n"); //创建基本的D3D对象,设备,交换链,视窗等 if (FAILED(my_d3d_haha.CompileTheShader())) return FALSE; else printf("CompileTheShader ----OK!\n"); if (FAILED(my_d3d_haha.CreateGraph()))return FALSE; else printf("CreateGraph ----OK!\n"); my_d3d_haha.Run(); return 0; }
void InitGoogleLogging() { if (google::IsGoogleLoggingInitialized()) { LOG(INFO) << "Google logging was already initialized, no action taken"; } else { #ifdef _MSC_VER FILE* file; freopen_s(&file, "stderr.log", "w", stderr); #else std::freopen("stderr.log", "w", stderr); #endif google::SetStderrLogging(google::INFO); google::SetLogDestination(google::FATAL, "glog/Principia/FATAL."); google::SetLogDestination(google::ERROR, "glog/Principia/ERROR."); google::SetLogDestination(google::WARNING, "glog/Principia/WARNING."); google::SetLogDestination(google::INFO, "glog/Principia/INFO."); FLAGS_v = 1; // Buffer severities <= |INFO|, i.e., don't buffer. FLAGS_logbuflevel = google::INFO - 1; google::InitGoogleLogging("Principia"); LOG(INFO) << "Initialized Google logging for Principia"; LOG(INFO) << "Principia version " << base::kVersion << " built on " << base::kBuildDate; // TODO(egg): by (compiler) for (ARCH, OS). } }
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdParam, int nCmdShow) { #ifdef DEBUG _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); //_CrtSetBreakAlloc(157); AllocConsole(); FILE* console; freopen_s(&console, "CONOUT$", "wt", stdout); #endif CGameManager *GameManager = CGameManager::GetInstance(); GameManager->initialize(600, 600); GameManager->changeScene(new CStartScene()); GameManager->run(); #ifdef DEBUG FreeConsole(); #endif return 0; }
void enable() { HWND h = ::GetConsoleWindow(); if (h) { ::ShowWindow(h, SW_SHOW); } else { FILE* new_file; ::AllocConsole(); freopen_s(&new_file, "CONIN$", "r", stdin); freopen_s(&new_file, "CONOUT$", "w", stdout); freopen_s(&new_file, "CONOUT$", "w", stderr); } }
int main() { FILE *f; freopen_s(&f, "input.txt", "r", stdin); freopen_s(&f, "output.txt", "w", stdout); char ch[100]; int i; gets_s(ch, sizeof(ch)); for (i = strlen(ch)-1; i >= 0; i--) { printf("%c", ch[i]); } return 0; }
int main() { FILE *f; freopen_s(&f, "input.txt", "r", stdin); freopen_s(&f, "output.txt", "w", stdout); char a[10], b[10]; int c; gets_s(a, sizeof(a)); gets_s(b, sizeof(b)); scanf_s("%d", &c); strcat_s(a, sizeof(a), b); printf("%d",atoi(a) + c); return 0; }
void init_console(void) { int Mode; struct _CONSOLE_SCREEN_BUFFER_INFO sbi; HANDLE Hstd; FILE *stream; Hstd = GetStdHandle(STD_INPUT_HANDLE); AllocConsole(); GetConsoleMode(Hstd, (LPDWORD)&Mode); SetConsoleMode(Hstd, Mode & 0xFFFFFFEF); GetConsoleScreenBufferInfo(Hstd, &sbi); sbi.dwSize.Y = 4096; SetConsoleScreenBufferSize(Hstd, sbi.dwSize); freopen_s(&stream, "conin$", "r", stdin); freopen_s(&stream, "conout$", "w", stdout); freopen_s(&stream, "conout$", "w", stderr); }
int main() { FILE *f; freopen_s(&f, "input.txt", "r", stdin); freopen_s(&f, "output.txt", "w", stdout); int tall[7]; for (int i = 0; i < 7; i++) scanf_s("%d", &tall[i]); qsort(tall, sizeof(tall) / sizeof(int), sizeof(int), compare); for(int i =6;i>=5;i--) printf("%d\n", tall[i]); return 0; }
void consoleOpen() { //Check if application does not have a console already open if (GetStdHandle(STD_OUTPUT_HANDLE) == NULL) { AllocConsole(); if (int code = AttachConsole(GetCurrentProcessId())) { tserror("AttachConsole failed with code %", code); } FILE* fp = nullptr; errno_t e = 0; tsassert(!(e = freopen_s(&fp, "CONOUT$", "w", stdout))); tsassert(!(e = freopen_s(&fp, "CONIN$", "r", stdin))); //tsassert(!(e = freopen_s(&fp, "CONERR$", "w", stderr))); //todo: fix opening of stderr //Synchronise with standard library console functions/objects (cout/cin/cerr) std::ios::sync_with_stdio(); } ts::global::getLogger().addStream(&getConsoleStreamInstance()); }