Answer to Question #18219 in C++ for harpreet
write a function in c++ which will take a string and return the word count.each saparated by single space.
1
2012-11-07T12:22:38-0500
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
int count(string str) {
stringstream ss;
ss << str;
int n = 0;
while (ss >> str)
& n++;
return n;
}
int main() {
cout << count("asdasd asd as das da sd as dasdasdsad");
return 0;
}
Need a fast expert's response?
Submit order
and get a quick answer at the best price
for any assignment or question with DETAILED EXPLANATIONS!
Learn more about our help with Assignments:
C++
Comments
Leave a comment