64 693
Assignments Done
99,3%
Successfully Done
In September 2018

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!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions