Shr*_*van 4 c++ xcode c++11 visual-studio-code c++17
我正在尝试在 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;
}
Run Code Online (Sandbox Code Playgroud)
当我尝试使用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
Run Code Online (Sandbox Code Playgroud)
显然这只是 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>是 GCC 的内部标头,您不应该使用它,它不可移植。
删除#include<bits/stdc++.h>
已安装的写入#include<vector>并#include<iostream>
删除使用名称空间 std它被认为是不好的做法,因此您的代码应该如下所示:
#include <vector>
#include <iostream>
int main()
{
// Create an empty vector
std::vector<int> vect;
vect.push_back(10);
vect.push_back(20);
vect.push_back(30);
for (int x : vect)
std::cout << x << " ";
return 0;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
12957 次 |
| 最近记录: |