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!

asked Jul 13, 2020 at 13:23
Shravan

7511 silver badge77 bronze badges

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;
}
answered Jul 13, 2020 at 13:31
yaodav

1,05688 silver badges2626 bronze badges
  • 2
    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

    Jul 13, 2020 at 13:37

  • 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

    Jul 13, 2020 at 13:40

  •  
    I've added some more info, if that helps!

    – Shravan

    Jul 14, 2020 at 0:46

  •  
    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

    Jul 14, 2020 at 5:59

  •  
    solved the issue, and subsequent issue comes again, so I continue comment out the error line. It worked!

    – Jackson

    Feb 3 at 10:37

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

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.

    Sep 14, 2020 at 17:47

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!

answered Nov 22, 2020 at 18:50
Chrissi

16111 silver badge66 bronze badges
  •  
    Any answer that recommends either editing or explicitly using the bits/stdc++.h header is, IMHO, utterly misleading.

    Nov 22, 2020 at 19:26

  •  
    According to this answer MacOSX does not have the file uchar.h so 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

    Nov 22, 2020 at 22:43 

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.

Cristik

29.2k2424 gold badges8686 silver badges122122 bronze badges
answered Jul 13, 2021 at 8:52
Archies Singh

1111 bronze badge
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

ERROR: <bits/stdc++.h>, 'cstdalign' file not found, running C++17的更多相关文章

  1. <bits/stdc++.h>头文件介绍(包含源代码)

    注:转自http://blog.csdn.net/charles_dong2/article/details/56909347,同为本人写的,有部分修改. 之前在一个小OJ上刷题时发现有人是这么写的: ...

  2. C++标准库头文件<bits/stdc++.h>

    在使用GNU GCC Compiler的时候,你可以包含一个头文件<bits/stdc++.h>,便可以使用C++中的各种标准库,而不用一个一个包含进来. 这在acm比赛中是一种常用的做法 ...

  3. 关于#include <bits/stdc++.h>

    经常看人写#include <bits/stdc++.h>却不知道是干啥的? #include<bits/stdc++.h>包含了目前c++所包含的所有头文件 对比: #inc ...

  4. C++万能头文件<bits/stdc++.h>的内容与优缺点

    最近发现了一个C++的头文件bits/stdc++.h,听说这是一个几乎包含了所有C++库函数的头文件,就想更深入的了解一下,下面是头文件内容 // C++ includes used for pre ...

  5. C++ 中头文件<bits/stdc++.h>的优缺点

    在编程竞赛中,我们常见一个头文件: #include <bits/stdc++.h> 发现它是部分C++中支持的一个几乎万能的头文件,包含所有的可用到的C++库函数,如<istrea ...

  6. 详细步骤:手动添加bits/stdc++.h到vs2017

    本机环境:win10系统 64位 vs2017 最近码代码时偶然发现了bits/stdc++.h这个头文件(万能头文件),基本上所有的代码只要用了这个头文件就不再写其他头文件了. 看到它就仿佛开启了新 ...

  7. VS2022不能使用<bits/stdc++.h>的解决方案

    •<bits/stdc++.h>介绍  #include<bits/stdc++.h>  包含了目前 C++ 所包含的所有头文件,又称万能头文件,简直是开挂一般的存在. 你编程 ...

  8. Visual Studio 中使用万能头文件 #include <bits/stdc++.h>

    最近开始使用VS,之前用的DEV C++软件可直接使用 #include <bits/stdc++.h>  ,但VS中并没有,为了使用方便,可直接在VS中添加此头文件,方法如下: 1.在安 ...

  9. 为VisualStudio2017添加bits/stdc++.h

    在算法编程中经常有人只写一个头文件"bits/stdc++.h" 其实这个是很多头文件的集合,写了它后相当于包含了所有常用的C++头文件,可是需要注意的是并不是所有的OJ系统都支持 ...

  10. Macbook上sublime的C++11弥补bits/stdc++.h的配置

    如果在windows配置过的话这次会容易很多.相关博客很多了,我这里保存一下我借鉴并成功的配置: 关于自己build的C++,文件类型为sublime-build,直接扔在它给出的user文件夹即可, ...

随机推荐

  1. CF1817E Half-sum

    题意 有一个大小为 \(N\) 的非负整数集合 \(A\),每次你可以从集合中取任意两个数,并将它们的平均数放回序列.不停操作,知道集合最后剩下两个数.请求出这两个数的差的绝对值的最大值对 \(10^ ...

  2. 利用生成式预训练Transformer实现智能问答与人机交互

    目录 利用生成式预训练Transformer实现智能问答与人机交互 随着人工智能技术的不断发展,智能问答和人机交互已经成为了人工智能领域中的重要研究方向.在智能问答中,机器能够以自然的方式与人类进行对 ...

  3. 为什么使用ioutil.ReadAll 函数需要注意

    1. 引言 当我们需要将数据一次性加载到内存中,ioutil.ReadAll 函数是一个方便的选择,但是ioutil.ReadAll 的使用是需要注意的. 在这篇文章中,我们将首先对ioutil.Re ...

  4. 【Linux】部署Nginx

    1.先安装gcc-c++编译器 yum install gcc-c++ yum install -y openssl openssl-devel 2.再安装pcre包 yum install -y p ...

  5. 瞬间抠图!揭秘 ZEGO 绿幕抠图算法背后的技术

    抠图是图像处理中最常见的操作之一,指的是将图像中需要的部分从画面中精确的提取出来. 抠图的主要功能是为了后期的合成做准备.在 Photoshop 中,抠图的方法有很多种,最常见的有通道抠图.蒙版抠图. ...

  6. The server time zone value '?泄???????' is unrecognized or represents more t

    hibernate配置文件如下 运行在服务器上,报错如下 解决方案: 在jdbc连接的url后面加上serverTimezone=GMT即可解决问题,因为是数据库和系统时区差异所造成的, 即 < ...

  7. flex布局入门

    一.简介 Flexible 单词意思是灵活的意思,flex布局又称为弹性布局或弹性盒子布局 Flex布局(Flexible Box Layout)是CSS3引入的一种布局模型,它旨在提供一种灵活且高效 ...

  8. 面试题 01.03. URL化

    面试题 01.03. URL化 简单 URL化.编写一种方法,将字符串中的空格全部替换为%20.假定该字符串尾部有足够的空间存放新增字符,并且知道字符串的"真实"长度.(注:用Ja ...

  9. Angular: 点击一次按钮,增加一个元素

    解决方案 思路 在组件的typesscript文件中,创建一个数组来存储每个按钮的信息 在模板中使用 *ngFor 指令来循环渲染按钮列表 在按钮事件的处理函数中,每次点击按钮时向按钮数组添加一个新的 ...

  10. 达梦数据库: SQL查询报错《不是 GROUP BY 表达式解决方法》

    报错信息: ****: 第4 行附近出现错误: 不是 GROUP BY 表达式 修改办法: 达梦可以配置兼容参数,COMPATIBLE_MODE=4,静态参数,需要重启数据库后生效! sp_set_p ...