shizaero

Untitled

Jun 20th, 2023
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.63 KB | None | 0 0
  1. #include "log_duration.h"
  2.  
  3. #include <iostream>
  4.  
  5. using namespace std;
  6.  
  7. class StreamUntier {
  8. public:
  9.     // добавьте конструктор, деструктор
  10.     // и дополнительные поля класса при необходимости
  11.     StreamUntier(istream* wave)
  12.     {
  13.         tied_before_ = wave.tie(nullptr);
  14.     }
  15.    
  16.     ~StreamUntier(){
  17.         cin.tie(tied_before_);
  18.     }
  19. private:
  20.     ostream* tied_before_;
  21. };
  22.  
  23. int main() {
  24.     LOG_DURATION("\\n with tie"s);
  25.  
  26.     StreamUntier guard(cin);
  27.     int i;
  28.     while (cin >> i) {
  29.         cout << i * i << "\n"s;
  30.     }
  31.  
  32.     return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment