【发布时间】:2020-11-02 16:55:18
【问题描述】:
我正在尝试在 macOS Catalina 上的 Visual Studio Code 中运行一段代码。 代码:
#include <bits/stdc++.h>
using namespace std;
int main()
{
// Create an empty vector
vector<int> vect;
vect.push_back(10);
vect.push_back(20);
vect.push_back(30);
for (int x : vect)
cout << x << " ";
return 0;
}
当我尝试使用 coderunner 扩展 运行代码时,我收到错误:
[Running] cd "/Users/VSC_Files/" && g++ -std=c++17 helloworld.cpp -o helloworld && "/Users/VSC_Files/"helloworld
In file included from helloworld.cpp:1:
/usr/local/include/bits/stdc++.h:57:10: fatal error: 'cstdalign' file not found
#include <cstdalign>
^~~~~~~~~~~
1 error generated.
[Done] exited with code=1 in 1.465 seconds
显然这只是 C++11 的错误,那我为什么会收到这个错误呢?我也有最新的 Xcode 更新版本和 VSCode 的最新稳定版本。
稍后编辑和添加
另外,我想补充一点,我手动添加了 bits/stdc++.h 文件,而它以前不存在。
另外,当我在运行时将 g++ -std=c++17 更改为 g++ 时,程序运行并显示正确的输出。带有如下所示的警告。helloworld.cpp:13:15: warning: range-based for loop is a C++11 extension [-Wc++11-extensions]
mt 笔记本电脑的默认 C++ 版本有问题吗?请帮忙!
【问题讨论】:
-
永远不要使用#include <bits/stdc++.h>
-
@yaodav 是的,我意识到这确实有效。但我想知道为什么我在使用
时指出的错误即将到来。有什么想法吗? -
我很惊讶在 SO 上搜索
bits/stdc++.h并没有让您几乎每天都遇到类似问题 -
重新打开。这个头当然是不可移植的,但如果它在那里,它应该可以工作......
-
g++ --version为您打印什么?
标签: c++ xcode c++11 visual-studio-code c++17