Slay
Slay

Reputation: 231

Compiling error that says 'std::basic_string<charT, _Traits, _Alloc>

The question was to iterate through a paragraph until an empty line is met.

Here's the code that's giving me the error mentioned in the title

#include <iostream>
#include <string>
#include <vector>
int main()
{
    using namespace std;
    string word;
   vector<string>text;
   while(cin>>word)
   {
       text.push_back(word);
   }
   for(auto it = text.begin(); it != text.end() && !(*it).empty; it++)
    {
        cout<<*it<<endl;
    }
}

What is causing the error, and what's the fix?

I'm a beginner, just started iterators.

Upvotes: 0

Views: 276

Answers (1)

mattn
mattn

Reputation: 7723

empty is a function.

#include <iostream>
#include <string>
#include <vector>
int main()
{
    using namespace std;
    string word;
   vector<string>text;
   while(cin>>word)
   {
       text.push_back(word);
   }
   for(auto it = text.begin(); it != text.end() && !(*it).empty(); it++)
    {
        cout<<*it<<endl;
    }
}

Upvotes: 3

Related Questions