I have buffer, let's say 65536 bytes long. How can I read stdin into that buffer as fast as possible (using IO hardware) without any check for newline or '\0' characters. I have a guarantee that the number of characters in stdin will always match my buffer.
So far I have this:
#include <iostream>
#include <stdio.h>
#define BUFFER_LENGTH 65536
int main()
{
std::ios::sync_with_stdio(false);
setvbuf(stdout, NULL, _IONBF, BUFFER_LENGTH);
char buffer[BUFFER_LENGTH];
// now read stdin into buffer
// fast print:
puts(buffer); // given buffer is null terminated
return 0;
}
Is there something similar to puts()
that will fast read into buffer instead of console?