View Single Post
Old 10-28-2004, 12:23 PM   #3 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
Valmont is on a distinguished road
Read this short thread. Read my comments on what is posted and learn:
Text program

Besides:
Quote:
Getting an entire line is a bit trickier, but since you don't need to do that, ...
You can't know in this stage. If you want to do some serious file checking (like format checking, integrity etc) one may use std::getline() instead.

The code below is just bad.
Quote:
inFile >> aWord;
while (!inFile.eof()) {
if (isPalidrome(aWord))
numPalidromes++;

inFile >> aWord;
}
Quote:
int isPalidrome (string aWord) {
// Your code here
}
bool isPalidrome(const string& aWord){...}

Basically this is the code:
Code:
   ifstream inFile ("path/to/file.txt");
   if (!inFile)
   {
      cout << "Error opening file!\n";
      return -1;
   }

   string theWord;
   while (inFile >> theWord)
   {
      if ( /* check_for_palidrome_with_theWord() */ )
      {
         cout<<theWord<<endl;
      }
   }

   //If file-reading loop exits before EOF has been reached, something is wrong.
   if( !inFile.eof() )
   {
      cout<<"ERROR: Something went wrong during processing of file."<<endl;
   }
__________________

Last edited by Valmont; 10-28-2004 at 12:54 PM.
Valmont is offline   Reply With Quote