C++11 编译警告: 'auto' 更改含义 - 解决方法
"sm4_passwd.cpp:473:16: warning: 'auto' changes meaning in C++11; please remove it [-Wc++0x-compat]\n for (const auto &c : input) 不适用c++11,怎么改,让编译通过" 在C++11之前,我们不能使用"auto"关键字来推断迭代器的类型。相反,我们需要明确指定迭代器的类型。要解决这个问题,您可以将代码更改为以下形式:\n\ncpp\nfor (std::string::const_iterator it = input.begin(); it != input.end(); ++it) {\n const auto &c = *it;\n // 其他代码\n}\n\n\n这样我们明确指定了it的类型为std::string::const_iterator,并使用*it来获取迭代器指向的元素。然后我们将其赋值给const auto &c来声明并初始化c。\n\n请确保将上述代码放置在原始的for循环的替代位置。
原文地址: https://www.cveoy.top/t/topic/p94I 著作权归作者所有。请勿转载和采集!