Dont read it line by line. Instead, read it word by word. The check if each word is a valid real number. Example:
int main(){
ifstream fileIn("input.txt");
string word;
unsigned int count = 0;
while( fileIn >> word )
{
if( isRealNumber( word ) ){ //you need to implement isRealNumber
++count;
}
}
}
Note in the above I assume each words are separated by spaces
firstPerson
Senior Poster
3,923 posts since Dec 2008
Reputation Points: 841
Solved Threads: 608
Read a word fin >> word;
Increment counter numwords++;
WaltP
Posting Sage w/ dash of thyme
10,505 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944