Advertisement
Alex_tz307

COUT

Sep 10th, 2020
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.30 KB | None | 0 0
  1. class OutParser
  2. {
  3. private:
  4.     char *buff;
  5.     int sp;
  6.  
  7.     void write_ch(char ch)
  8.     {
  9.         if (sp == 50000)
  10.         {
  11.             fwrite(buff, 1, 50000, stdout);
  12.             sp = 0;
  13.             buff[sp++] = ch;
  14.         }
  15.         else
  16.         {
  17.             buff[sp++] = ch;
  18.         }
  19.     }
  20.  
  21.  
  22. public:
  23.  OutParser() {
  24.         buff = new char[50000]();
  25.         sp = 0;}
  26.     ~OutParser()
  27.     {
  28.         fwrite(buff, 1, sp, stdout);
  29.         fclose(stdout);
  30.     }
  31.  
  32.     OutParser& operator << (int vu32)
  33.     {
  34.         if (vu32 <= 9)
  35.         {
  36.             write_ch(vu32 + '0');
  37.         }
  38.         else
  39.         {
  40.             (*this) << (vu32 / 10);
  41.             write_ch(vu32 % 10 + '0');
  42.         }
  43.         return *this;
  44.     }
  45.  
  46.     OutParser& operator << (long long vu64)
  47.     {
  48.         if (vu64 <= 9)
  49.         {
  50.             write_ch(vu64 + '0');
  51.         }
  52.         else
  53.         {
  54.             (*this) << (vu64 / 10);
  55.             write_ch(vu64 % 10 + '0');
  56.         }
  57.         return *this;
  58.     }
  59.  
  60.     OutParser& operator << (char ch)
  61.     {
  62.         write_ch(ch);
  63.         return *this;
  64.     }
  65.     OutParser& operator << (const char *ch)
  66.     {
  67.         while (*ch)
  68.         {
  69.             write_ch(*ch);
  70.             ++ch;
  71.         }
  72.         return *this;
  73.     }
  74. };
  75.  
  76. OutParser fout;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement