Answer to Question #18219 in C++ for harpreet

Question #18219
write a function in c++ which will take a string and return the word count.each saparated by single space.
1
Expert's answer
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!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS