Nib*_*bor 1 c++ string dictionary c++11
我有这段代码来制作几个字符串小写(请参阅此SO帖子).
void some_free_standing_function(std::string solver, std::map<std::string, option_t> opts) {
for (auto & c : solver) c = tolower(c);
for (auto p : opts)
for (auto & c : p.first)
c = tolower(c);
}
Run Code Online (Sandbox Code Playgroud)
第一个基于范围的for似乎是编译,最后一个不是:Clang给了我error: cannot assign to variable 'c' with const-qualified type 'const char &'.
为什么第一个通过但不通过第二个,因为它们完全相同?