Please read the guide .
Please answer the question in detail
#include <iostream> #include <string> using namespace std; int main() { string line; int count = 0; cout << "Enter a line of text: "; getline(cin, line); for (int i = 0; i < line.length(); i++) { if (line[i] == ' ') { count++; } } cout << "Number of words in the line: " << count + 1 << endl; return 0; }
Doubtly is an online community for engineering students, offering:
Get the pro version for free by logging in!
5.7k questions
5.1k answers
108 comments
557 users