I am writing a c++ program to find the number of words in a string using stringstream in c++ but my compiler is giving the above error. I am using vsCode on my macbook air to do this and using the Xcode's GNU compiler. I also tried to write the code in the CLION ide which also gives the same error. Here is the code.
#include <iostream>
using namespace std;
int countWords(string str)
{
// breaking input into word using string stream
stringstream s(str); // Used for breaking words
string word; // to store individual words
int count = 0;
while (s >> word)
count++;
return count;
}
// Driver code
int main()
{
string s = "using stringstream class in cplusplus";
cout << " Number of words are: " << countWords(s);
return 0;
}
Please help me with this.
Aucun commentaire:
Enregistrer un commentaire