76 836
Assignments Done
Successfully Done
In June 2019

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.
Expert's answer
#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!


No comments. Be first!

Leave a comment

Ask Your question

Privacy policy Terms and Conditions