Write a program in C++, to count the number of words in a line of text
#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;
}