Cool fast IO implementation!!!

cin
cout
fastinputoutput
fastio
implementation

#1

Any hints or improvements are welcome.

This is a cin/cout (very) fast replacement. This redefines cin/cout so, just include this code to boost I/O speed, and everything should work like cin/cout.
Output only works fast when ONLINE_JUDGE is defined, else it flushes constantly, which is desirable when code is tested locally.

Voila le code: [Fast IO][1]
[1]: http://ideone.com/fOK6CW


#2

wicked :D… had an enjoyable moment reading this code… cool


#3

Very cool!!!

A small suggestion:

It shall be better to change the following line:

inline IO& operator << (char * s) { while (*s) putChar(*s++); return *this; }

into:

inline IO& operator << (const char * s) { while (*s) putChar(*s++); return *this; }

Otherwise there can be compiler warnings when output constant strings like: cout << " ";


#4

GOD code !!


#5

Not sure if it is a bug. But when I have 2 space-separated characters in stdin like,

STDIN

a b

and MY CODE is

char x,y;

cin>>x>>y;

x stores ‘a’ and y stores ’ ’ where it should avoid spaces and store ‘b’ (since it emulates cin).

Otherwise, it’s a charm :slight_smile:


#6

this does not work on codeforces , why is it so?


#7

this does not work on codeforces , why is it so?


#8

Pity the Markdown vandalizes the _'s used in the code :frowning: I guess people would just have to copy-paste from the “edit” option.


#9

FIXED: Link to code is provided.


#10

@mukel I am implementing this code but I am getting An error that i am not able to understand. Can you help? http://ideone.com/Ke9Y42 here is the link


#11

Fixed #includes issue and link updated. Any feedback, extension or even some shrinked version is apreciated, enjoy


#12

Done, + added very basic usage example, enjoy!!!


#13

Fixed bug with sign, + little improvement reading signed integers. Tested on SPOJ INTEST problem.


#14

Can you please help me, I’m trying to compile your code on Windows, I’m using Code::Blocks(gnu gcc compiler) and I’m getting next warnings: ‘getc_unlocked’ was not declared in this scope , ‘putc_unlocked’ was not declared in this scope