Is there any way of making file input/output in c++?
I’d say the simplest way to get speedy file IO in C or C++ is to read the maximum amount of data possible in one go.
In my experience, something like this will be much slower:
unsigned char byte;
FILE * reader;
if((reader = fopen("file","rb")))
{
while(!feof(reader))
fread( &byte,sizeof(unsigned char), 1, reader)
}
than something that reads more data in one go, like this:
unsigned char bytes[10];
FILE * reader;
if((reader = fopen("file","rb")))
{
while(!feof(reader))
fread(byte,sizeof(unsigned char), 10, reader)
}
Of course, you’ll have to change the ‘10’ in fread to a variable that you modify to not read past the EOF.