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;
}