OK this is probably really simple, but for some reason when I pass through the ifstream variable inStream, the counter doesn't work...
when the counter is included in the OpenFile function it works fine...but when I place it in its proper function, and pass through inStream it doesn't. BTW elements is a private member of the class,
this is the class definitionCode://FILE NAME: readfile.cpp /* * definitions for class ReadFile */ //===================================== ReadFile::ReadFile() { elements = 0; } //===================================== void ReadFile::openFile( string fileName ) { ifstream inStream; inStream.open( fileName.c_str() ); //open user chosen file //check if filed open correctly, if not //show error message, and terminate if ( inStream.fail() ) { cout << "Input file opening for " << fileName << " failed. Exiting...\n\n"; exit(-1); } countElements( inStream ); inStream.close(); } //===================================== void ReadFile::countElements( ifstream inStream ) { string temp; //dummy var to keep the line //start counting elements procedure if(inStream.good()) { while(!inStream.eof() && inStream.good()) { getline(inStream,temp); elements++; } } /***************************************** ERROR CHECKING - DELETE ******************************************/ cout << "There are " << elements << " elements." << endl; inStream.close(); //close file }
Code://FILE NAME: readfile.h /* * File that reads in the file: * -the first pass, counts the number of elements in the file * -the second pass puts the file into the map * -the third pass makes the adjecency list */ class ReadFile { public: ReadFile(); //function declarations void openFile( string fileName ); void countElements( ifstream inFile ); void readIntoMap(); void readIntoList(); private: int elements; //number of elements }; #include "readFile.cpp"



LinkBack URL
About LinkBacks


