Is there a faster way to open and read files, this seems too slow.
I'm pretty new to C++, I wrote this small program to learn about file handeling, its a little program to display files to the screen like windows type or *nix's more program, it works ok but just seems very slow, is there a faster way to do this?
Code:
#include <windows.h>
#include <fstream.h>
#include <iostream.h>
#include <io.h>
int main(int argc, char * argv[])
{
char line[1000];
if(argc!=2)
{
cout << "Please specify a filename";
return 0;
}
if(access(argv[1], 00))
{
cout << "The file " << argv[1] << " does not exist";
return 0;
}
LARGE_INTEGER us;
long int t,a;
QueryPerformanceCounter(&us);
t = us.u.LowPart;
ifstream theFile;
theFile.open(argv[1]);
while(!theFile.eof())
{
theFile.getline(line,1000);
cout << line << endl;
}
theFile.close();
QueryPerformanceCounter(&us);
a = us.u.LowPart -t;
cout << a << " micro seconds";
return 0;
}
sorry for the long paste.
I included a benchmark to test how long it takes, I managed to half the time reading a line at a time instead of a char at a time.
Will be greatful for any ideas