gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-27 22:42:17 24 4
gpt4 key购买 nike

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

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com