Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #include <fcntl.h>
- #include <iostream>
- using namespace std;
- void SetupConsole()
- {
- if (!AttachConsole(ATTACH_PARENT_PROCESS)) {
- // We have no parent console, so create one
- AllocConsole();
- }
- // Attach invalid file descriptors to the console
- if (_fileno(stdin) < 0)
- freopen("CONIN$", "r", stdin);
- if (_fileno(stdout) < 0)
- freopen("CONOUT$", "w", stdout);
- if (_fileno(stderr) < 0)
- freopen("CONOUT$", "w", stderr);
- std::ios::sync_with_stdio();
- }
- int main(int argc, char **argv)
- {
- int x;
- SetupConsole();
- printf("printf!\n");
- cout << "cout!" << endl;
- cerr << "cerr!" << endl;
- cout << "enter a number: ";
- cin >> x;
- cout << "input:" << x << endl;
- Sleep(1000);
- }
Advertisement
Add Comment
Please, Sign In to add comment