Mega Code Archive

 
Categories / C++ Tutorial / String
 

Use cin in while loop to read string

#include <iostream> #include <string> using namespace std; int main() {      int count = 0;    string word;    while (cin >> word)    {         count++;    }    cout << count << " words.\n";    return 0; }