Advertisement
RobertDeMilo

RB2.8 Связанность потоков

Apr 16th, 2024
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.98 KB | None | 0 0
  1. // По умолчанию потоки cout и cerr связаны с потоком cin
  2. // Это может замедлять программы типа stdin -> stdout
  3. // Наряду с заменой endl на '\n' добавляйте cin.tie(nullptr) в начало своих программ
  4.  
  5. #include <iostream>
  6. #include <vector>
  7. #include <fstream>
  8.  
  9. #include "log_duration.h"
  10.  
  11. using namespace std;
  12.  
  13. int main()
  14. {
  15.     cin.tie(nullptr);
  16.  
  17.     {
  18.         LOG_DURATION("endl");
  19.        
  20.         for (int i = 0; i < 100'000; ++i)
  21.        {
  22.            int x;
  23.            cin >> x;
  24.            cout << x << endl;
  25.        }
  26.    }
  27.  
  28.    {
  29.        LOG_DURATION("'\\n'");
  30.        
  31.        for (int i = 0; i < 100'000; ++i)
  32.         {
  33.             int x;
  34.             cin >> x;
  35.             cout << x << '\n';
  36.         }
  37.     }
  38.  
  39.     /*cin.tie(nullptr);
  40.     cout << "Enter two integers: ";
  41.     int x, y;
  42.     cin >> x >> y;
  43.  
  44.     for (;;)
  45.     {
  46.  
  47.     }*/
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement