I was developing programs for reading data from files in C++. I came up with two different methods to do it. But am not sure which is efficient and i dont even know how to find the efficiencies of a program. I have given yu two snippets. Please somebody tell me how to analyse the efficiencies or tell me which is efficient.
ifstream inFile( "Data" );
if( !inFile ){
cerr << "Error :Unable to open the file";
return -1;
}
string word;
while( inFile >> word )
cout << word << endl ;
and the other method is :
FILE* input;
input = fopen("/home/jayanarayanan/Project/Data", "rb"); //file input
if ( input == NULL ) { perror (" Error opening File "); }
else{
char buffer[27];
char *in;
in = fgets (buffer, 28, input);
output << in;
}