【发布时间】:2020-06-20 04:02:19
【问题描述】:
我正在学习 C++ 的新功能,在 C++ 17 及更高版本中进行了更新。我已经将我的 VSCode 设置为使用 Microsoft 的 C/C++ 编译器扩展进行 C++ 编程,并且还为我的 clang 更新更新了 Xcode。 源代码:
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
vector <int> myints = {1, 2, 3, 4, 5, 6, 7, 8, 9};
for(int i : myints){
cout << i << " ";
}
cout << "\n";
// partition method from STL :
partition(myints.begin(), myints.end(), [](auto x){return xx%2 ==0;});
for(int i : myints){
cout << i << " ";
}
cout << "\n";
return 0;
}
有人对如何为 C++ 17 或更高版本更新 clang 有任何建议吗? 或其他解决我问题的扩展。 提前谢谢你。
【问题讨论】:
-
如果您提取(并添加到您的问题中)IDE 发出的编译命令,将会非常有帮助。您可能不需要更新编译器;您的错误消息表明它没有被告知使用现代 C++ 扩展(并建议一个标志来打开它们)。
-
您是否尝试过使用
-std=C++17?发生了什么? -
--std=C++17 工作正常。但是,如果有人在编译时仍然遇到任何问题,您可以使用 Jun Han 称为“Code Runner”的 vsCode 扩展。它将使用可用的最新编译器直接运行代码。
标签: c++ macos visual-studio-code clang c++17