gaofeng
gaofeng

Reputation: 403

Why dereferencing a string iterator yields a const char reference?

I have a nonconst string,when dereferencing its string iterator,i have found debug information show it had a type of const char reference.Why this happen?

string str{ "Hello,world" };
for (auto it = str.begin(); it != str.end(); ++it)
{
    *it = toupper(*it);
    cout << *it;
}

Using Visual studio 2015.

Upvotes: 0

Views: 73

Answers (1)

M.M
M.M

Reputation: 141554

If it yielded a const char reference then the code *it = toupper(*it); would fail to compile, since you cannot assign to a const.

Perhaps the debug information is wrong, or you misinterpret the debug information.

Upvotes: 4

Related Questions