Guest User

Untitled

a guest
Mar 23rd, 2017
300
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.91 KB | None | 0 0
  1. #include <windows.h>
  2. #include <fcntl.h>
  3. #include <iostream>
  4.  
  5. using namespace std;
  6.  
  7. void SetupConsole()
  8. {
  9.         if (!AttachConsole(ATTACH_PARENT_PROCESS)) {
  10.                 // We have no parent console, so create one
  11.                 AllocConsole();
  12.         }
  13.  
  14.         // Attach invalid file descriptors to the console
  15.         if (_fileno(stdin) < 0)
  16.                 freopen("CONIN$", "r", stdin);
  17.  
  18.         if (_fileno(stdout) < 0)
  19.                 freopen("CONOUT$", "w", stdout);
  20.  
  21.         if (_fileno(stderr) < 0)
  22.                 freopen("CONOUT$", "w", stderr);
  23.  
  24.         std::ios::sync_with_stdio();
  25. }
  26.  
  27.  
  28. int main(int argc, char **argv)
  29. {
  30.         int x;
  31.  
  32.         SetupConsole();
  33.  
  34.         printf("printf!\n");
  35.         cout << "cout!" << endl;
  36.         cerr << "cerr!" << endl;
  37.         cout << "enter a number: ";
  38.         cin >> x;
  39.         cout << "input:" << x << endl;
  40.  
  41.         Sleep(1000);
  42. }
Advertisement
Add Comment
Please, Sign In to add comment