首页 > 编程语言 >ERROR: <bits/stdc++.h>, 'cstdalign' file not found, running C++17

ERROR: <bits/stdc++.h>, 'cstdalign' file not found, running C++17

时间:2022-10-19 20:00:09浏览次数:76  
标签:std 13 17 c++ running Jul 2020 C++ include

Modified ​​1 year, 1 month ago​

Viewed 9k times


4

I'm trying to run a piece of code in Visual Studio Code, on macOS Catalina. The 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;
}

When I try to run the code using the coderunner extension, I get the error:

[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

Apparently this is an error only for C++11, then why am I getting this error? I have the latest updated Xcode version and the latest stable build of VSCode too.

EDITED AND ADDED LATER

Also, I would like to add that I manually added the ​​bits/stdc++.h​​ file, and that it wasn't there from before.

Also, when I change ​​g++ -std=c++17​​​ to just ​​g++​​​ when running, the program runs and shows the correct output. With a warning as shown below.
​​​helloworld.cpp:13:15: warning: range-based for loop is a C++11 extension [-Wc++11-extensions]​

Is there an issue with the default C++ version in mt laptop? Please help!

​c++​​​​xcode​​​​c++11​​​​visual-studio-code​​​​c++17​

​Share​

​Improve this question​

Follow

 

​edited Jul 14, 2020 at 0:44​

 

 

asked Jul 13, 2020 at 13:23

​Shravan​

7511 silver badge77 bronze badges

​Show 7 more comments​


5 Answers

Sorted by:

Trending sort available 

                         Highest score (default)                                                                     Trending (recent votes count more)                                                                     Date modified (newest first)                                                                     Date created (oldest first)                     


4

​#include<bits/stdc++.h>​​ is an internal header for the GCC and you are not supposed to use it, it's not portable.

remvoe the ​​#include<bits/stdc++.h>​​​ insted write ​​#include<vector>​​​ and ​​#include<iostream>​​​ also remove ​​using namespace std​​ it considered bad practice so you code shod look like this:

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

​Share​

​Improve this answer​

Follow

 

​edited May 19, 2021 at 13:14​

 

 

answered Jul 13, 2020 at 13:31

​yaodav​

1,05688 silver badges2626 bronze badges

​Add a comment​


3

I was having the same issue. First I installed gcc via homebrew

​brew install gcc​

To avoid conflict with the existing gcc (and g++) binaries, homebrew names the binary suffixed with version. At time of this comment, the latest was gcc-10.

You dont have to copy the ​​bits/stdc++.h​​​ after this. Just compile using ​​g++-<major-version-number>​​​ instead of ​​g++​​, which would use the homebrew installed binary instead of the default osx one. For me it is

​g++-10 -Wall -O2 -std=c++11 test.cpp -o test​

To check the binary name that homebrew installed you can look in the ​​/usr/local/bin​​ directory because thats where homebrew installs packages.

Also, make sure that ​​usr/local/bin​​​ is before ​​/usr/bin​​​ in your ​​$PATH​

​Share​

​Improve this answer​

Follow

 

answered Sep 14, 2020 at 17:45

​Himanshu Tanwar​

36822 silver badges1616 bronze badges

  • 1

    Also, I am not disagreeing with the other comments saying that we should not use​​bits/stdc++.h​​ and ​​using namespace std;​​ in our code. I put this here, because its good to know how to make it work if we have to use it. 
    –​​Himanshu Tanwar​​ ​​​Sep 14, 2020 at 17:47​​​

​Add a comment​


1

For me it worked to comment the following lines out in the file ​​bits/stdc++.h​​:

// #include <cstdalign>

...

// #include <cuchar>

The file is located in ​​/usr/local/include/bits/​​​ as well as in ​​/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/bits​​. I don't know if you have to do it in both files but the first one worked for me!


Update Dec 24: If you use the g++ with the command line, there is no need to move any file into any directory!

For example when I use the command: ​​g++ custom_file.cpp​​​ it works fine! In addition you can add ​​-std=c++11​​ to have the most needed functions. Also I don't have to move the ​​bits/stdc++.h​​ file after Xcode get's an update.

I hope this helps!

​Share​

​Improve this answer​

Follow

 

​edited Dec 24, 2020 at 0:03​

 

 

answered Nov 22, 2020 at 18:50

​Chrissi​

16111 silver badge66 bronze badges

​Add a comment​


1

I too got these error, and I solved these error by commenting out the ​​<cstdalign>​​ part.

After you comment out these line it will give 2 more errors - ​​cuchar not found​​​, and ​​<memory_resources> not found​​, comment both of them using " //" . It will not harm you stdc++.h file . And it will definitely work.

​Share​

​Improve this answer​

Follow

 

​edited Jul 13, 2021 at 13:17​

​Cristik​

29.2k2424 gold badges8686 silver badges122122 bronze badges

answered Jul 13, 2021 at 8:52

​Archies Singh​

1111 bronze badge

​Add a comment​


0

I am sharing steps to execute with sample code for array rotation which works with following commands

g++-10 -Wall -O2 -std=c++11 rotatearrayusingdeque.cpp

Then a.out file gets generated.

./a.out

sample code:

#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,r,i,j,temp=0,n1;
deque<int> v;
cin>>n>>r;
for(i=0;i<n;i++)
{
cin>>n1;
v.push_back(n1);

}
for(j=0;j<r;j++)
{
temp = v.front();
v.pop_front();
v.push_back(temp);
}
for(auto x:v)
{
cout<<x<<" ";
}
cout<<endl;

return 0;
}

Now, there will not be any error, Thanks



标签:std,13,17,c++,running,Jul,2020,C++,include
From: https://blog.51cto.com/u_15726470/5776475

相关文章

  • JDK-11.0.17 + Neo4j-4.4.12
    JDK安装下载地址:https://www.oracle.com/java/technologies/javase-downloads.html 注册Oracle账户,并下载,选择路径安装,将bin配置到环境变量PathNeo4j安装......
  • python进阶之路17 包的使用、collections、time、random模块
    包大白话:多个py文件的集合>>>:文件夹专业:内部含有__init__.py文件的文件夹(python2必须要求python3无所谓)包的具体使用虽然python3对包的要求降低了不需要__i......
  • VSCode搭建C和C++环境
    @目录前言下载安装设置.vscodec_cpp_properties.jsonlaunch.jsonsettings.json下载CodeRunner插件运行代码VSCode我个人的配置项设置前言说明下如何在VSCode下面搭建C/......
  • 实验3 数组、指针与现代C++标准库
    实验目的知道什么是类模板,会正确定义和使用简单的类模板能够描述数组的特性,会使用C++语法正确定义和访问内置数组,知道其局限性能够解释指针变量的特性,会使用C++语法正......
  • 实验3 数组,指针与现代c++标准库
    实验五:Info.hpp1#include<iostream>2#include<string>3#include<iomanip>4usingnamespacestd;5classInfo6{7private:8......
  • CF1743 E - FTL(线性DP)
    E-FTL(线性DP)题意​ 现在你有两支激光枪,枪A伤害为\(p_1\),冷却时间为\(t_2\);枪B伤害为\(p_2\),冷却时间为\(t_2\)。敌人的护甲为s,可以抵消每一次攻击中的s点伤害。请问最......
  • C++11 实现一个自动注册的工厂
    之前在项目代码里面看到同事写了个自动注册的工厂类,虽然当时我看不懂,但我大受震撼。今天又重新温习了一下这种写法,分享给大家,可见学好C++是多么的重要。实现动机工厂方法......
  • 做题记录整理图论/最短路/dp/记忆化搜索 P3953 [NOIP2017 提高组] 逛公园(2022/10/19)
    P3953[NOIP2017提高组]逛公园https://122720.blog.luogu.org/p3953-ti-xie-ji-yi-hua-sou-suo大佬讲得挺好的,我就不写了#include<bits/stdc++.h>#definefor1(i,a,b......
  • 做题记录整理数据结构/线段树 P1712 [NOI2016] 区间(2022/10/17)
    P1712[NOI2016]区间由于现在做题比较杂,所以就不标号码了感觉应该算是思维题?刚开始没想到完全用线段树后来看了题解如果想到线段树的话这题剩下的东西就可以很自然的......
  • C++类模型漫谈(二)
    系统基于32位,MSVC编译器,VS开发工具1、通过对象对成员函数的调用,默认会给参数传进去一个this指针,该指针为对象的首地址,这个过程通常被编译器隐藏起来了。对象直接调用成员......