简体   繁体   English

为什么解引用字符串迭代器会产生const char引用?

[英]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.

相关问题 取消引用字符串迭代器会产生int - Dereferencing string iterator yields int 取消引用字符迭代器 - Dereferencing char iterator 取消引用集合迭代器时,将“ string&”绑定到“ const string”时出错 - Error binding 'string&' to 'const string' when dereferencing a set iterator 为什么取消引用std :: set时需要const <T> ::迭代者? - Why const is required when dereferencing std::set<T>::iterator? std :: basic_string类型的非const引用的init无效 <char> :: const_iterator&来自std :: basic_string类型的rvalue <char> ::为const_iterator - Invalid init of non-const reference of type std::basic_string<char>::const_iterator& from rvalue of type std::basic_string<char>::const_iterator 为什么解引用字符串向量迭代器需要括号? - Why does dereferencing a string vector iterator need parentheses? 为什么在“ const typename iterator_traits”中忽略“ const” <RandomIterator> ::参考”? - Why “const” is ignored in “const typename iterator_traits<RandomIterator>::reference”? 字符串引用和const char指针的函数重载 - Function overloading for string reference and const char pointer 解引用字符串迭代器和性能影响 - Dereferencing string iterator and performance impact c++ map/set iterator 不可解引用 --- map<const char *, string> - c++ map/set iterator not dereferencable --- map<const char *, string>
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM