c++ - 为什么取消引用字符串迭代器会产生 const char 引用?

标签 c++ iterator

我有一个非常量字符串,当取消引用它的字符串迭代器时,我发现调试信息显示它有一个 const char 引用类型。为什么会这样?

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

使用 Visual Studio 2015。

最佳答案

如果它产生一个 const char 引用,那么代码 *it = toupper(*it); 将无法编译,因为您不能分配给一个 const

可能调试信息有误,或者你误解了调试信息。

关于c++ - 为什么取消引用字符串迭代器会产生 const char 引用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47764773/

相关文章:

c++ - 指针对指针的动态二维数组

c++ - 抛出 'std::system_error'实例后终止调用

c++ - c++ 中汉明距离的更快形式(可能利用标准库)?

c++ - 使用不可移动/不可复制的类型创建 hana 元组

c++ - begin() 如何知道要返回哪种返回类型(const 或 non-const)?

c++ - "Out of bound iterator"为空集

c++ - 为什么声明私有(private)基类会使类型名称不可访问?

c++ - 遍历容器的最佳方式

c++ - Top Down Shooter 中 0x000FBA44 处的未处理异常

python - 在 python 中调用生成器时引发 Unresolved 引用错误