i am trying to find out total number of words in a sentence but i am facing a problem. when i run the following code and enter the string in for example hi how are you. i am fine. whats up#
then it displays the number of words fine Total: 9
when enter this input hi how are you. i am fine. whats up #
notice there is space between "up" and "#"
then its output is Total: 10
which is wrong
and when i enter this
Well one problem is you are only accounting for ' ' spaces, so when you push return (enter) you don't account for the fact that it will not be a space but a '\r' or '\n' (can't remember which)
Another problem is you are saying anything counts as a word as long as it's not a ' ' so when you have "whats up #" you do in fact have three words, because "#" is a word by your definition.
You may want to change your cin functionality- here's a useful function :
Thank you, Duoas. It's nice to see an example of how an advanced function like typedef helps to make the code more readable without having to use extra comments to explain what's going on.
Once you overload the operator '>>' , how do you go back to it's standard implementation?