提问者:小点点

错误:<bits/stdc++.h>,找不到“cstdalign”文件,正在运行C++17


我正在尝试在macOS catalina上用Visual Studio代码运行一段代码。 代码:

#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; 
} 

当我尝试使用CoderRunner扩展运行代码时,我得到了错误:

[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版本。 请救命!


共1个答案

匿名用户

remove#includeinsted写入#include#include还使用命名空间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; 
} 

相关问题


MySQL Query : SELECT * FROM v9_ask_question WHERE 1=1 AND question regexp '(bits|stdc++.h|找不到|cstdalign|文件|运行|c++17)' ORDER BY qid DESC LIMIT 20
MySQL Error : Got error 'repetition-operator operand invalid' from regexp
MySQL Errno : 1139
Message : Got error 'repetition-operator operand invalid' from regexp
Need Help?