我有一个非常量字符串,当取消引用它的字符串迭代器时,我发现调试信息显示它有一个 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/