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