ERROR: <bits/stdc++.h>, 'cstdalign' file not found, running C++17
Modified 1 year, 1 month ago
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!
- 9
- 1@yaodav Yes, I realise that does work. But I was wondering why the error I indicated when we use <bits/stdc++.h> was coming. Any idea?– Shravan
- I'm amazed that a search for
bits/stdc++.hon SO does not give you an almost daily hit for a similar question– rioV8 - 2Reopened. This header is of course not portable, but if it's there, it should work...
5 Answers
Highest score (default)
Trending (recent votes count more)
Date modified (newest first)
Date created (oldest first)
#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;
}
- 2Yes, I realise that does work. But I was wondering why the error I indicated when we use <bits/stdc++.h> was coming. Any idea?– Shravan
- 1<bits/stdc++.h> is internal header could be that part of the header files its including are not in the macOS c++lib is also indecate that from the error message - he cant find "#include <cstdalign>"– yaodav
- I've added some more info, if that helps!– Shravan
- According to what version of g++ you have 4.2.1 I don't think it supports c++ 11 try updating your gcc version.– yaodav
- solved the issue, and subsequent issue comes again, so I continue comment out the error line. It worked!– Jackson
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
- 1Also, I am not disagreeing with the other comments saying that we should not use
bits/stdc++.handusing 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.
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!
- Any answer that recommends either editing or explicitly using the
bits/stdc++.hheader is, IMHO, utterly misleading. - According to this answer MacOSX does not have the file
uchar.hso you cannot#include <cuchar>. Maybe you can download it e.g. from here and paste it to the right directory. I haven't tried this yet.– Chrissi
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.

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
ERROR: <bits/stdc++.h>, 'cstdalign' file not found, running C++17的更多相关文章
- <bits/stdc++.h>头文件介绍(包含源代码)
注:转自http://blog.csdn.net/charles_dong2/article/details/56909347,同为本人写的,有部分修改. 之前在一个小OJ上刷题时发现有人是这么写的: ...
- C++标准库头文件<bits/stdc++.h>
在使用GNU GCC Compiler的时候,你可以包含一个头文件<bits/stdc++.h>,便可以使用C++中的各种标准库,而不用一个一个包含进来. 这在acm比赛中是一种常用的做法 ...
- 关于#include <bits/stdc++.h>
经常看人写#include <bits/stdc++.h>却不知道是干啥的? #include<bits/stdc++.h>包含了目前c++所包含的所有头文件 对比: #inc ...
- C++万能头文件<bits/stdc++.h>的内容与优缺点
最近发现了一个C++的头文件bits/stdc++.h,听说这是一个几乎包含了所有C++库函数的头文件,就想更深入的了解一下,下面是头文件内容 // C++ includes used for pre ...
- C++ 中头文件<bits/stdc++.h>的优缺点
在编程竞赛中,我们常见一个头文件: #include <bits/stdc++.h> 发现它是部分C++中支持的一个几乎万能的头文件,包含所有的可用到的C++库函数,如<istrea ...
- 详细步骤:手动添加bits/stdc++.h到vs2017
本机环境:win10系统 64位 vs2017 最近码代码时偶然发现了bits/stdc++.h这个头文件(万能头文件),基本上所有的代码只要用了这个头文件就不再写其他头文件了. 看到它就仿佛开启了新 ...
- VS2022不能使用<bits/stdc++.h>的解决方案
•<bits/stdc++.h>介绍 #include<bits/stdc++.h> 包含了目前 C++ 所包含的所有头文件,又称万能头文件,简直是开挂一般的存在. 你编程 ...
- Visual Studio 中使用万能头文件 #include <bits/stdc++.h>
最近开始使用VS,之前用的DEV C++软件可直接使用 #include <bits/stdc++.h> ,但VS中并没有,为了使用方便,可直接在VS中添加此头文件,方法如下: 1.在安 ...
- 为VisualStudio2017添加bits/stdc++.h
在算法编程中经常有人只写一个头文件"bits/stdc++.h" 其实这个是很多头文件的集合,写了它后相当于包含了所有常用的C++头文件,可是需要注意的是并不是所有的OJ系统都支持 ...
- Macbook上sublime的C++11弥补bits/stdc++.h的配置
如果在windows配置过的话这次会容易很多.相关博客很多了,我这里保存一下我借鉴并成功的配置: 关于自己build的C++,文件类型为sublime-build,直接扔在它给出的user文件夹即可, ...
随机推荐
- 如何从AWS中学习如何使用AmazonVPC
目录 如何从 AWS 中学习如何使用 Amazon VPC? 随着 AWS 的迅速发展,Amazon VPC(Virtual Private Cloud)已经成为了一种非常重要的云计算基础设施.VPC ...
- 自动化SQL注入工具——Sqlmap
Sqlmap – 简介 Sqlmap是一个自动化检测和利用SQL注入漏洞的免费开源工具 1.支持对多种数据库进行注入测试,能够自动识别数据库类型并注入 2.支持多种注入技术,并且能够自动探测使用合适的 ...
- C语言基础-基础指针
文章目录 指针 前言 1.什么是指针 2.指针的使用 (1)指针的定义 (2)指针的赋值 (3)指针类型 (4)如何使用指针 3.野指针 (1)导致野指针的原因 ① 未初始化指针 ②指针越界访问 ③指 ...
- String s=new String(“hello”)的执行过程
一. 介绍 String 是Java.long包下的String类,是一个特殊的引用类型,用于表示字符串.它提供了许多方法来操作和处理字符串,比如连接.截取.查找.替换等.String类内部使用字符数 ...
- fastposter v2.16.0 让海报开发更简单
fastposter v2.16.0 让海报开发更简单 fastposter海报生成器是一款快速开发海报的工具.只需上传一张背景图,在对应的位置放上组件(文字.图片.二维.头像) 点击代码直接生成各种 ...
- python数据处理:获取Dataframe中的一列或一行
解决方案 df['w'] #选择表格中的'w'列,使用类字典属性,返回的是Series类型 df.w #选择表格中的'w'列,使用点属性,返回的是Series类型 df[['w']] #选择表格中的' ...
- Typescript: 当出现错误时,不编译文件成js文件
在tsconfg.json文件中添加如下选项 "noEmitOnError": true, /* Disable emitting files if any type checki ...
- 记录一次解决数据库连接池连接泄露BUG
1 BUG现象 系统并发请求,系统停滞无法使用,所有接口都是无法与后端进行交互的状态,系统并没有宕机 2 BUG的业务流程 插入分数方法 涉及插入表ABCD 加了声明式事务 查询分数方法 涉及表ABC ...
- JDK中动态库加载路径问题,一文讲清
前言 本周协助测试同事对一套测试环境进行扩容,我们扩容很原始,就是新申请一台机器,直接把jdk.resin容器(一款servlet容器).容器中web应用所在的目录,全拷贝到新机器上,servlet容 ...
- Python中字符串截取
# 截取字符串时,如果位数不够,Python不会报错,而是返回空字符串 # 这是因为Python中的字符串是不可变的,所以当我们尝试访问一个不存在的索引时,Python会返回空字符串而不是报错 # 示 ...
