DragonOsman

cust_std_lib_facilities.cpp

Sep 19th, 2017
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.97 KB | None | 0 0
  1. #include "cust_std_lib_facilities.h"
  2. #include <iostream>
  3. #include <chrono>
  4. #include <stdexcept>
  5. #include <random>
  6. #include <string>
  7.  
  8. int randint(int min, int max)
  9. {
  10.     using namespace std;
  11.  
  12.     auto seed = chrono::system_clock::now().time_since_epoch().count();
  13.     static default_random_engine ran(seed);
  14.     return uniform_int_distribution<>{min, max}(ran);
  15. }
  16.  
  17. void keep_window_open()
  18. {
  19.     using namespace std;
  20.     cin.clear();
  21.     cout << "Please enter a character to exit\n";
  22.     char ch;
  23.     cin >> ch;
  24.     return;
  25. }
  26.  
  27. void keep_window_open(std::string s)
  28. {
  29.     using namespace std;
  30.     if (s == "") return;
  31.     cin.clear();
  32.     cin.ignore(120, '\n');
  33.     for (;;) {
  34.         cout << "Please enter " << s << " to exit\n";
  35.         string ss;
  36.         while (cin >> ss && ss != s)
  37.             cout << "Please enter " << s << " to exit\n";
  38.         return;
  39.     }
  40. }
  41.  
  42. void error(const std::string& s)
  43. {
  44.     using namespace std;
  45.     throw runtime_error(s);
  46. }
  47.  
  48. void error(const std::string& s, const std::string& s2)
  49. {
  50.     error(s + s2);
  51. }
Add Comment
Please, Sign In to add comment