Why can a C++ iterator be dereferenced although it isn't a pointer?

后端 未结 3 1386
野趣味
野趣味 2021-01-15 14:53

I\'m reading C++ Primer 5th, and I encounter code that looks like this:

    string s(\"some string\");
    if (s.begin() != s.end())
    {
      auto it = s.         


        
3条回答
  •  轮回少年
    2021-01-15 15:11

    The iterator type (and this is something that is obscured by using the magical auto keyword) is a complicated thing, not a primitive object.

    When you ask for*it, you are given a reference to the char at that position. Hence you can modify it.

提交回复
热议问题