假设以下代码:
#include <iostream>
#include <vector>
#include <string>
int main() {
std::vector<std::string> lines;
lines.push_back("line");
for (const auto& s : lines) {
std::cout << s;
}
}
在 for 循环的那一行,我收到以下警告:
C26493 Don't use C-style casts that would perform a static_cast downcast, const_cast, or reinterpret_cast.
谁能解释一下这是从哪里来的?我正在使用 Visual Studio 2017 Community Edition 版本 15.2。
最佳答案
如 this bug report 所示当插入到 basic_iostream
中时,它似乎只发生在 std::string
类型上。此错误已解决,但尚未发布,所以现在您只能等待。
关于c++ - 在 vector 上使用基于范围的 for 循环时,CppCoreChecker C 样式转换警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44776507/