fork download
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. string name,temp,result;
  8. int words=0,size;
  9. cout << "Enter a word:";
  10. getline(cin,name);
  11. size = name.size();
  12. for (int i = 0; i < size; i++) {
  13. if (name[i] == ' ') {
  14. words += 1;
  15. }
  16. }
  17. cout << words;
  18. }
Success #stdin #stdout 0s 15232KB
stdin
abc def ghi jkl mno
stdout
Enter a word:4