single quotes vs double quotes string

hey people this is not so much a problem rather than curious question

so I run the code below and I get the following error

error: ISO C++ forbids comparison between pointer and integer [-fpermissive]|

how come when you dereference the iterator which points to a string it has to be in single quotes rather than double?

also the error message message is quite cryptic how are we comparing a pointer to an integer sure we are comparing a char to a string or a string to a string?

if I remove the double quotes " t " and put single quotes for a char it works fine

(ps yes this is a silly way to remove a character from a string when we could use string.erase overloaded function with a string instead of an iterator but just doing it for fun)

thanks

1
2
3
4
5
6
7
8
9
10
11
12
13
14
  int main(){

for(string::iterator it = str.begin(); it != str.end();){

        if(*it == "t"){

            it = str.erase(it);
        }else{

          it++;
        }


}
it is an iterator to a char, so *it is a char. A char is a single byte number.

"t" is a pointer to a const char; that char happens to be the letter t.

Comparing a number to a pointer is generally forbidden. It makes no sense.

't' is a char, so that comparison is number to number. Fine.

To summarise, "t" is a pointer to a char, 't' is a char.
ah ok,so the string class uses pointers internally to chars to represent a string?

thanks Repeater
Topic archived. No new replies allowed.