I read in geeksforgeeks and added the template to it so that it can work for every integer data types such as long
, long long
and int
.
#include <bits/stdc++.h>
using namespace std;
template<typename T>
void fs(T& x) // For faster scanning of input
{
int n = 1;
char c = getchar();
x = 0;
for (; (c < 48 || c>57) && c != '-'; c = getchar());
if (c == '-') {
n = -1;
c = getchar();
}
for (; (c < 47 && c < 58); c = getchar())
x = (x << 1) + (x << 3) + c - 48;
x = n * x;
}
int main()
{
int test;
fs(test);
cout << test;
return 0;
}
But when I tried executing it, the output is shown as 0
and not the input number. Is the above code wrong?