Why is this giving me an error

Why am i getting an error here, the !b->empty() gives error

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
  #include <iostream>
#include <string>
#include <vector>
using std::cin; using std::cout; using std::endl; using std::string;
using std::vector;
int main()
{
	string text = "words that are writen here are lowercase";
	if (text.begin() != text.end()) {
		for (string::iterator b = text.begin(); b!= text.end() && !b->empty(); ++b) {

		}
	}
	cin.sync();
	cin.get();
	return 0;
}
Try to replace it with
!b.empty()



Edit :
Sorry...!! Confused between iterators and containers ..
Last edited on
> string::iterator b
when doing `b->empty()' you are dereferencing `b' and getting a char
¿what methods does a char have?


We may be able to suggest a solution if know what you intended to do.
this is one of the questions i got where the program needs to know its reached a newline using iterators, the char itself doesnt have the empty funtion but dereferencing it like this does
(*b).empty() which is the same as b->empty() both give same error
If you want to check the new line character, do it like so:

for (string::iterator b = text.begin(); b!= text.end() && ((*b) != '\n'); ++b) {
Topic archived. No new replies allowed.