C++ 如何在 Xcode 中包含 <bits/stdc++>
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28994148/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I include <bits/stdc++> in Xcode
提问by Omar
I have tried to include the header file bits/stdc++ in my C++ code, but it seems the compiler doesn't support it. Is there any way to make it work?
我试图在我的 C++ 代码中包含头文件 bits/stdc++,但似乎编译器不支持它。有没有办法让它工作?
I use OS X Yosemite 10.10.2 and Xcode 6.1.1.
我使用 OS X Yosemite 10.10.2 和 Xcode 6.1.1。
回答by Reza
You can do it by copying stdc++.h file from here: https://gist.github.com/reza-ryte-club/97c39f35dab0c45a5d924dd9e50c445f
您可以通过从这里复制 stdc++.h 文件来实现:https: //gist.github.com/reza-ryte-club/97c39f35dab0c45a5d924dd9e50c445f
Then you can include the file in your c++ file like this:
然后你可以像这样将文件包含在你的 C++ 文件中:
//suppose the file is in your home folder, here my username is reza
#include "/Users/reza/stdc++.h"
回答by u5985526
Mac OS X 10.9+ no longer uses GCC/libstdc++ but uses libc++ and Clang.
Mac OS X 10.9+ 不再使用 GCC/libstdc++,而是使用 libc++ 和 Clang。
After the XCode 6.0.1 update the headers are now located here:
在 XCode 6.0.1 更新后,标题现在位于此处:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1
so, get the stdc++.h file from here,then creat bitsdirectory in the above long address, and copy the file stdc++.hto the bitsdirectory.
所以,从这里获取stdc++.h文件,然后在上面的长地址中创建bits目录,将stdc++.h文件复制到bits目录下。
回答by Sachin Kumar
Since, bits/stdc++ is a GNU GCC extension, whereas OSX uses the clang compiler.
因为 bits/stdc++ 是 GNU GCC 扩展,而 OSX 使用 clang 编译器。
You have to create bitsdirectory inside /usr/local/include and then make a header file stdc++.hinside bits and paste the contents of this gistinside it. Then, it should compile as expected.
您必须在 /usr/local/include 中创建bits目录,然后在 bits 中创建一个头文件stdc++.h并将此 gist的内容粘贴到其中。然后,它应该按预期编译。
Since, /usr directory is hidden by default on Mac OSX.
因为, /usr 目录在 Mac OSX 上默认是隐藏的。
- Open Finder.
- Click Goon menu bar then click Go to folderor Press Command+Shift+G directly.
- Enter the path /usr/local/include
- Now proceed as mentioned above.
- 打开查找器。
- 单击菜单栏上的Go,然后单击Go to folder或直接按 Command+Shift+G。
- 输入路径/usr/local/include
- 现在按照上面提到的进行。
回答by Brendan Lesniak
You can't. X-Code uses LLVM Toolchain with Clang for the compiler, while <bits/stdc++>
is specific to the GNU Compiler Toolchain.
你不能。X-Code 使用带有 Clang 的 LLVM 工具链作为编译器,而<bits/stdc++>
特定于 GNU 编译器工具链。
Second, you shouldn't be using that header in the first place, as stated by everyone else.
其次,正如其他人所说,您一开始就不应该使用该标题。
回答by Ravibhushan Kumar
Before Adding the bits/stdc++.h to your mac os platform, the First things are to figure out where your include files are present. To figure out which include file is getting utilized within you mac environment.
在将 bits/stdc++.h 添加到您的 mac os 平台之前,首先要弄清楚包含文件的位置。找出在您的 mac 环境中使用的包含文件。
Run this command in terminal:
echo "" | gcc -xc - -v -E
在终端中运行此命令:
回声"" | gcc -xc - -v -E
This will provide the details of gcc environment in your platform
这将提供您平台中 gcc 环境的详细信息
Apple LLVM version 10.0.1 (clang-1001.0.46.4)
Target: x86_64-apple-darwin18.7.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
"/Library/Developer/......."
ignoring nonexistent directory
"/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/local/include"
ignoring nonexistent directory
"/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/Library/Frameworks"
#include "..." search starts here:
#include <...> search starts here:
/usr/local/include
/Library/Developer/CommandLineTools/usr/lib/clang/10.0.1/include
/Library/Developer/CommandLineTools/usr/include
/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/include
/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/System/Library/Frameworks (framework directory)
End of search list.
# 1 "<stdin>"
# 1 "<built-in>" 1
# 1 "<built-in>" 3
# 361 "<built-in>" 3
# 1 "<command line>" 1
# 1 "<built-in>" 2
# 1 "<stdin>" 2
- Go to the include path. ex: /usr/local/include Create a bits folder and add stdc++.hfile.
- 转到包含路径。例如:/usr/local/include 创建一个 bits 文件夹并添加stdc++.h文件。
回答by moon87
Copy the content of this header file to clipboard from Link: https://gist.github.com/reza-ryte-club/97c39f35dab0c45a5d924dd9e50c445f
Run following in terminal :
- mkdir /usr/local/include/bits
- vim /usr/local/include/bits/stdc++.h
- Switch to insert mode (press i) and Paste clipboard content
- Save/Exit (Esc + : + w + q + Enter)
Try compliation of your source code
将此头文件的内容从链接复制到剪贴板:https: //gist.github.com/reza-ryte-club/97c39f35dab0c45a5d924dd9e50c445f
在终端中运行以下:
- mkdir /usr/local/include/bits
- vim /usr/local/include/bits/stdc++.h
- 切换到插入模式(按 i)并粘贴剪贴板内容
- 保存/退出(Esc + : + w + q + Enter)
尝试编译您的源代码
回答by Sahil Rajput
- Open Finder.
- Click Go on menu bar then click Go to folder or Press Command+Shift+G directly.
- Enter the path /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1
- 打开查找器。
- 单击菜单栏上的 Go,然后单击 Go to folder 或直接按 Command+Shift+G。
- 输入路径/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1
Now, get the stdc++.h file from here, then create bits directory in the above long address, and copy the file stdc++.h to the bits directory.
现在,从这里获取stdc++.h文件,然后在上面的长地址中创建bits目录,将stdc++.h文件复制到bits目录下。
回答by Shahriar Nasim Nafi
1.Download the stdc++.h file from https://gist.github.com/eduarc/6....
1.从https://gist.github.com/eduarc/6下载stdc++.h文件....
2.In Finder CTRL + SHIFT +G and open /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include/
2.在 Finder 中 CTRL + SHIFT +G 并打开 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include/
3.Create the folder bits and copy the downloaded file here.
3.创建文件夹bits并将下载的文件复制到这里。
回答by Akash Srinivasan
- Open Finder.
- Click Go on menu bar then click Go to folder or Press Command+Shift+G directly.
- Enter the path or c/p this path directly
- 打开查找器。
- 单击菜单栏上的 Go,然后单击 Go to folder 或直接按 Command+Shift+G。
- 输入路径或者直接c/p这个路径
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1
- Then create bits directory in the above long address.
- Now, get the stdc++.h file from [here][1].
- and copy the file stdc++.h to the bits directory.
- 然后在上面的长地址中创建bits目录。
- 现在,从 [here][1] 获取 stdc++.h 文件。
- 并将文件 stdc++.h 复制到位目录。