Advertisement
Wigoo

util.cpp

Nov 10th, 2014
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.92 KB | None | 0 0
  1. int getch();
  2. void cls();
  3. int eingabe_Int();
  4.  
  5.  
  6. #include <cstdlib>
  7. #include <stdio.h>
  8. #include <iostream>
  9. #include <termios.h>
  10. #include <unistd.h>
  11. #include <windows.h>
  12.  
  13. using namespace std;
  14.  
  15. int eingabe_Int(){
  16.         double zahl;
  17.         int temp;
  18.     while(true){
  19.         cin >> zahl;
  20.         if(cin.fail()){
  21.             cin.clear();
  22.             cin.ignore();
  23.             cout << "Eingabe ist kein gültiger Int-wert, bitte wiederholen" << endl;
  24.             continue;
  25.         }
  26.         temp = zahl;
  27.         if(temp != zahl){
  28.             cout << "Eingabe ist kein gültiger Int-wert, bitte wiederholen" << endl;
  29.             continue;
  30.         }
  31.         return zahl;
  32.     }
  33. }
  34.  
  35. int getch( ) {
  36.   struct termios oldt,
  37.                  newt;
  38.   int            ch;
  39.   tcgetattr( STDIN_FILENO, &oldt );
  40.   newt = oldt;
  41.   newt.c_lflag &= ~( ICANON | ECHO );
  42.   tcsetattr( STDIN_FILENO, TCSANOW, &newt );
  43.   ch = getchar();
  44.   tcsetattr( STDIN_FILENO, TCSANOW, &oldt );
  45.   return ch;
  46. }
  47.  
  48. void cls()
  49.   {
  50.   HANDLE                     hStdOut;
  51.   CONSOLE_SCREEN_BUFFER_INFO csbi;
  52.   DWORD                      count;
  53.   DWORD                      cellCount;
  54.   COORD                      homeCoords = { 0, 0 };
  55.  
  56.   hStdOut = GetStdHandle( STD_OUTPUT_HANDLE );
  57.   if (hStdOut == INVALID_HANDLE_VALUE) return;
  58.  
  59.   /* Get the number of cells in the current buffer */
  60.   if (!GetConsoleScreenBufferInfo( hStdOut, &csbi )) return;
  61.   cellCount = csbi.dwSize.X *csbi.dwSize.Y;
  62.  
  63.   /* Fill the entire buffer with spaces */
  64.   if (!FillConsoleOutputCharacter(
  65.     hStdOut,
  66.     (TCHAR) ' ',
  67.     cellCount,
  68.     homeCoords,
  69.     &count
  70.     )) return;
  71.  
  72.   /* Fill the entire buffer with the current colors and attributes */
  73.   if (!FillConsoleOutputAttribute(
  74.     hStdOut,
  75.     csbi.wAttributes,
  76.     cellCount,
  77.     homeCoords,
  78.     &count
  79.     )) return;
  80.  
  81.   /* Move the cursor home */
  82.   SetConsoleCursorPosition( hStdOut, homeCoords );
  83.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement