getchar_unlocked in windows undeclared
c++, scanf
Solution
`getchar_unlocked` is not a C or C++ standard function and therefore it's no surprise that it doesn't work on Windows. It is a POSIX standard I think, but Windows compilers don't support all POSIX functions.
If you replaced `getchar_unlocked` with `getchar`, it would kind of work, although the algorithm doesn't seem quite right.
You could do this with conditional compilation, like this for instance
#ifdef _WINDOWS
// no getchar_unlocked on Windows so just call getchar
inline int getchar_unlocked() { return getchar(); }
#endif
Problem
Here is my code: ``` #include <stdio.h> void scan(int* i) { int t=0; char c; bool negative=false; c=getchar_unlocked(); while(c<'0'&&c>'9') { if(c=='-') negative=true; c=getchar_unlocked(); } while(c>'0'&&c<'9') { t=(t<<3)+(t<<1)+c-'0'; c=getchar_unlocked(); } if(negative) t=~(t-1); //negative *i=t; } int main(int argc, char const *argv[]) { int i; scan(&i); return 0; } ``` I know that the function defined here as `scan` is faster than `scanf` and is very useful on programming competitions. But for some reason this code is not working on Windows and is working on Linux. What do I do to get it working on Windows? I am using the `g++` compiler from Dev-C++.