栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

MAC用户如何为Xocde配置#include <bits/stdc++.h>的万能头文件

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

MAC用户如何为Xocde配置#include <bits/stdc++.h>的万能头文件

前言

工欲善其事,必先利其器

众所周知,ACM里有一个强大的神器便是“bits/stdc++.h”,然而在Xcode中include这个头文件却报错,原因是stdc++.h是gcc特有的,而Xcode的c++编译器是clang,所以不能用万能头

解决方法就是手写一个stdc++.h用

方法1:手动设置
  • 打开访达

  • 按“⇧⌘G”来调出“前往文件夹”,或者点左上角倒数第三个按钮“前往”,选择“前往文件夹”

  • 输入Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1

  • 你就会进入一个如下的文件夹

  • 你需要建一个名为bits的文件夹

  • 进入bits的文件夹后,建立一个TXT格式的文稿,并改名为stdc++.h

  • 将如下的代码粘贴进stdc++.h内

    // C++ includes used for precompiling -*- C++ -*-
    
    // Copyright (C) 2003-2013 Free Software Foundation, Inc.
    //
    // This file is part of the GNU ISO C++ Library.  This library is free
    // software; you can redistribute it and/or modify it under the
    // terms of the GNU General Public License as published by the
    // Free Software Foundation; either version 3, or (at your option)
    // any later version.
    
    // This library is distributed in the hope that it will be useful,
    // but WITHOUT ANY WARRANTY; without even the implied warranty of
    // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    // GNU General Public License for more details.
    
    // Under Section 7 of GPL version 3, you are granted additional
    // permissions described in the GCC Runtime Library Exception, version
    // 3.1, as published by the Free Software Foundation.
    
    // You should have received a copy of the GNU General Public License and
    // a copy of the GCC Runtime Library Exception along with this program;
    // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
    // .
    
    
    
    // 17.4.1.2 Headers
    
    // C
    #ifndef _GLIBCXX_NO_ASSERT
    #include 
    #endif
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    
    #if __cplusplus >= 201103L
    #include 
    #include 
    #include 
    //#include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #endif
    
    // C++
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    
    #if __cplusplus >= 201103L
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #endif
    
  • 保存就可以了

方法2:命令行
  • 打开终端

    cd /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1
    sudo mkdir bits
    sudo touch stdc++.h
    sudo vim stdc++.h
    
    // C++ includes used for precompiling -*- C++ -*-
    
    // Copyright (C) 2003-2013 Free Software Foundation, Inc.
    //
    // This file is part of the GNU ISO C++ Library.  This library is free
    // software; you can redistribute it and/or modify it under the
    // terms of the GNU General Public License as published by the
    // Free Software Foundation; either version 3, or (at your option)
    // any later version.
    
    // This library is distributed in the hope that it will be useful,
    // but WITHOUT ANY WARRANTY; without even the implied warranty of
    // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    // GNU General Public License for more details.
    
    // Under Section 7 of GPL version 3, you are granted additional
    // permissions described in the GCC Runtime Library Exception, version
    // 3.1, as published by the Free Software Foundation.
    
    // You should have received a copy of the GNU General Public License and
    // a copy of the GCC Runtime Library Exception along with this program;
    // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
    // .
    
    
    
    // 17.4.1.2 Headers
    
    // C
    #ifndef _GLIBCXX_NO_ASSERT
    #include 
    #endif
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    
    #if __cplusplus >= 201103L
    #include 
    #include 
    #include 
    //#include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #endif
    
    // C++
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    
    #if __cplusplus >= 201103L
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #endif
    
方法3:有手就行

如果上面的两个方法都不行,那就介绍一个有手就行的方法,

打开:这个网站

下载到本地

打开命令行,进入存放该文件的路径下,输sudo sh Xcode-bits-stdc++.sh,键入管理员密码后即可自动运行脚本,完成配置,真点击就送

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/648405.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号