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

MAC用户如何为Xocde配置#include <bitsstdc++.h>的万能头文件,第1张

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,键入管理员密码后即可自动运行脚本,完成配置,真点击就送

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5650600.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存