C++快速读入

作者: JesHrz | 来源:发表于2018-08-05 12:20 被阅读41次
    namespace IO
    {
        inline char nc() {
            static char buf[100000], *p1 = buf, *p2 = buf;
            return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF : *p1++;
        }
        template<typename T>
        inline T read() {
            char ch = nc(); 
            T sum = 0;
            while (!(ch >= '0'&&ch <= '9'))
            {
                ch = nc();
                if (ch == EOF)  return EOF;
            }
            while (ch >= '0'&&ch <= '9')
            {
                sum = sum * 10 + ch - 48;
                ch = nc();
                if (ch == EOF)  return EOF;
            }
            return sum;
        }
    }
    

    调用方式
    int n = IO::read<int>();
    long long n = IO::read<long long>();
    判断EOF
    while((n = IO::read<int>()) != EOF)

    相关文章

      网友评论

        本文标题:C++快速读入

        本文链接:https://www.haomeiwen.com/subject/krkbvftx.html