int main()
{
ifstream inputFileStream; // declare the input file stream
int lettersArray[ LIMIT]; // count occurrences of characters
char c = ' '; // input character
int i; // loop counter
string fileName = "MacbethEnglish.txt";
// open input file and verify
inputFileStream.open( fileName.c_str()); // Convert C++ string to expected C-style string
if( !inputFileStream.is_open()) {
cout << "Could not find input file. Exiting..." << endl;
exit( -1);
}
// initialize lettersArray count values
for (i=0; i<LIMIT; i++) {
lettersArray[ i] = 0;
}
// Process input one character at at time, echoing input
// Note that the input skips leading spaces, which is why we don't see
// them as part of the output.
cout << "Reading characters from a file... " << endl;
**while( inputFileStream >> c)** {
// convert alphabetic input characters to upper case
if( isalpha( c)) {
c = toupper( c);
lettersArray[ c-'A']++; // update letter count, using the character as the index
// cout << c << " "; // Takes too long to display when enabled
}
}
What is exactly is while( inputFileStream >> c) the bolded line supposed to be doing? I do not understand the condition/or operator. I am trying to change the code from reading a text file to reading a string instead. I am not so sure how to do this. I wanted to create an identical function but changing the functionality for strings instead of txt files.