快读

0AND1STORY

2019-01-25 11:05:23

Personal

今天写了一个不错的快读,跟大家分享。 废话不多说,代码如下: ```cpp #ifndef _FASTIO_H_ #define _FASTIO_H_ #include <cstdio> #include <cctype> namespace fastio { class FastIn { public: template<typename T> inline void readSingle(T& x) { x = 0; int f = 1; char ch = getchar(); while (!isdigit(ch) && ch != '-') ch = getchar(); if (ch == '-') f = -1, ch = getchar(); while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar(); x *= f; } template<typename T> FastIn& operator>>(T& x) { readSingle(x); return *this; } }; FastIn fastin; } #endif ``` 使用方法如下: ```cpp #include <cstdio> #include "fastio.h" using namespace std; int main() { int a, b, c; fastio::fastin >> a >> b >> c; //可使用using namespace fastio; //然后用fastin >> a >> b >> c; printf("%d %d %d\n", a, b, c); return 0; } ```