fast io c++ code example

Example 1: fast io c++

#include <bits/stdc++.h>
using namespace std;

template <typename T> void in(T& x) // fast input
{
    x = 0; T f = 1;
    char ch = getchar();
    while (!isdigit(ch)) f = ch == '-' ? - f : f, ch = getchar();
    while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
    x *= f;
}

template<typename T> void out(T n) //fast output
{ 
	bool neg = 0; 

	if (n < 0) 
		n *= -1, neg = 1; 

	char snum[20]; 
	int i = 0; 
	do
	{ 
		snum[i++] = n % 10 + '0'; 
		n /= 10; 
	} 

	while (n); 
	--i; 

	if (neg) 
		putchar('-'); 

	while (i >= 0) 
		putchar(snum[i--]); 

	putchar('\n'); 
} 

main() { //My Test
  	int n;
	in(n);
  	out(n);
}

Example 2: fast io c++

#define FastIO ios_base::sync_with_stdio(false); cin.tie(NULL);

Example 3: fast io c++

fastio.pythonanywhere.com   
/* A tool to optimize execution time of C++ codes by replacing methods of
reading and writing variables */

Tags:

Cpp Example