[英]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? 我有一个非常量字符串,当取消引用其字符串迭代器时,我发现调试信息表明它具有一种const char引用类型。为什么会这样?
string str{ "Hello,world" };
for (auto it = str.begin(); it != str.end(); ++it)
{
*it = toupper(*it);
cout << *it;
}
Using Visual studio 2015. 使用Visual Studio 2015。
If it yielded a const char reference then the code *it = toupper(*it);
如果产生const char引用,则代码*it = toupper(*it);
would fail to compile, since you cannot assign to a const
. 将无法编译,因为您无法分配给const
。
Perhaps the debug information is wrong, or you misinterpret the debug information. 调试信息可能错误,或者您误解了调试信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.