手动添加bits/stdc++.h到vs2017(万能头文件)

本文详细介绍了如何在Visual Studio 2017中配置使用bits/stdc++.h头文件,通过手动添加stdc++.h源码到VS的头文件库,实现快速调用大量C++标准库功能。

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.youkuaiyun.com/maitianpt/article/details/82155083


本机环境:win10   64位   vs2017

最近码代码时偶然发现了bits/stdc++.h这个头文件(万能头文件),基本上所有的代码只要用了这个头文件就不再写其他头文件了。

看到它就仿佛开启了新世界(也有缺点,就是导致编译速度变慢,不过一般可以忽略不计)。

但是当我想用它时却发现:

看来要手动添加喽【如果安装了MinGW的直接在文件夹里面找到bits这个文件夹,把里面内容复制粘贴到vs的头文件库里面】

如果没有安装MinGW,那就跟着我来做以下步骤:

1.新建txt文档,把以下代码(stdc++.h源码)复制进去:

 

// C++ includes used for precompiling -*- C++ -*-
 
// Copyright (C) 2003-2015 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
// <http://www.gnu.org/licenses/>.
 
/** @file stdc++.h
 *  This is an implementation file for a precompiled header.
 */
 
// 17.4.1.2 Headers
 
// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
 
#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif
 
// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
 
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

2.把txt文档改名stdc++.h

3.打开vs2017的安装目录,右上角搜索MSCV,打开这个文件夹:

然后依次打开文件夹“14.15.26726”》》“include”

在“include”目录下新建文件夹“bits”,然后把刚才的bits/stdc++.h移入。

4. 大功告成


————————————————

<think> 首先,用户的问题是:“我想查找在DevC++中解决无法使用bits/stdc++.h头文件问题的方法 请问DevC++无法使用bits/stdc++.h头文件的解决方法”。这是在询问如何在DevC++中解决无法使用bits/stdc++.h头文件的问题。 参考站内引用: - 引用[1]:提到#include<bits/stdc++.h>是一个常见的引用方式,用于包含C++标准库中的所有头文件,简化代码编写。 - 引用[2]:指出通过将下载的文件放置在IDE的包含目录中,可以让编译器识别并使用这个万能头文件,使用时只需包含#include "bits/stdc++.h"。 用户的问题集中在DevC++中无法使用这个头文件,所以我需要提供针对DevC++的解决方法。 根据我的知识: - bits/stdc++.h不是C++标准的一部分;它是一个常见的非标准头文件,通常用于竞赛编程。 - 在DevC++中,默认可能不包含这个头文件,所以用户需要手动添加。 - 解决方法通常涉及下载bits/stdc++.h文件并将其放在正确的编译器目录中。 步骤: 1. **下载bits/stdc++.h文件**:用户可以从网上下载这个头文件。例如,从GitHub或其他资源下载。 2. **找到DevC++的包含目录**:在DevC++中,需要将文件放在编译器的include目录下。 - 通常路径可能是:C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\版本号\include\c++\ 或类似路径。 3. **放置文件**:将下载的bits/stdc++.h文件复制到include目录下的bits子目录。如果bits目录不存在,需要创建它。 4. **测试**:重启DevC++,并编写一个简单程序包含#include<bits/stdc++.h>来测试。 为了回答清晰: - 结构要清晰:逐步引导用户解决问题。 - 使用中文:所有回答用中文。 - 添加引用标识:在回答末尾添加引用标识。 - 生成相关问题:在最后添加相关问题。 回答结构: 1. 解释问题:简要说明为什么DevC++默认可能不支持bits/stdc++.h。 2. 提供解决方法:分步骤讲解如何下载和放置文件。 3. 测试建议:告诉用户如何测试是否成功。 4. 添加引用标识:基于提供的引用。 5. 生成相关问题。 引用标识: - 引用[1]和[2]是关于bits/stdc++.h的一般信息,但我需要根据用户问题定制回答。 - 在回答末尾自然地添加引用标识,例如:[^1] 相关问题: - 基于主题,生成一些问题,如: 1. 如何检查DevC++的编译器路径? 2. 还有哪些IDE支持bits/stdc++.h? 3. 使用bits/stdc++.h的优缺点是什么? 确保回答真实可靠:基于常见解决方案。 </think> 根据您的查询,DevC++ 默认不支持 `bits/stdc++.h` 头文件,因为该头文件不是 C++ 标准库的一部分,而是由 GCC 编译器提供的一个非标准扩展。DevC++ 通常使用 MinGW 编译器(Windows 版 GCC),但可能未预装该文件。下面我将逐步解释解决方法,确保您能顺利使用该头文件。 ### 解决方法步骤 1. **下载 `bits/stdc++.h` 文件**: - 从可靠来源下载该头文件。推荐从 GitHub 仓库获取(例如:[GCC Mirror](https://github.com/gcc-mirror/gcc) 或专门资源站)。 - 下载链接示例:[点击下载 bits/stdc++.h](https://raw.githubusercontent.com/gcc-mirror/gcc/master/libstdc%2B%2B-v3/include/precompiled/stdc%2B%2B.h)(保存为 `bits/stdc++.h`)。 - 如果下载失败,可手动创建文件:新建文本文件,命名为 `bits/stdc++.h`,内容粘贴以下代码: ```cpp // C++ includes used for precompiling -*- C++ -*- // Copyright (C) 2003-2022 Free Software Foundation, Inc. ... // 标准库头文件列表(省略具体内容,实际需完整粘贴) ``` 完整内容参考 [GCC 官方仓库](https://github.com/gcc-mirror/gcc/blob/master/libstdc%2B%2B-v3/include/precompiled/stdc%2B%2B.h)。 2. **定位 DevC++ 的包含目录**: - 打开 DevC++,转到菜单栏的 "Tools" > "Compiler Options"。 - 在 "Directories" 选项卡下,选择 "Include Directories"。 - 添加或确认 MinGW 的 include 路径。典型路径为: - `C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\X.X.X\include\c++\`(`X.X.X` 是您的 GCC 版本号)。 - 如果路径不同,请根据您的安装位置调整。 3. **放置头文件到正确目录**: - 在 include 目录下创建 `bits` 子文件夹(如果不存在)。 - 例如:`C:\...\include\c++\bits\`。 - 将下载的 `bits/stdc++.h` 文件复制到该 `bits` 文件夹内。 - 确保文件权限允许读取(右键文件 > 属性 > 取消只读选项)。 4. **测试配置是否成功**: - 重启 DevC++。 - 新建一个 C++ 源文件(如 `test.cpp`),输入以下代码: ```cpp #include <bits/stdc++.h> using namespace std; int main() { vector<int> arr = {1, 5, 2, 4}; sort(arr.begin(), arr.end()); for (int num : arr) { cout << num << " "; } return 0; } ``` - 编译并运行程序。如果输出 `1 2 4 5`,则配置成功;如果报错,检查路径是否正确或文件内容是否完整。 ### 注意事项 - **兼容性**:此方法适用于 DevC++ 5.11 及以上版本(使用 MinGW-w64 编译器)。如果使用旧版 DevC++,建议升级到最新版[^1]。 - **备用方案**:如果问题持续,考虑手动包含所需头文件(如 `#include <vector>`、`#include <algorithm>`),避免依赖 `bits/stdc++.h`。 - **安全性**:下载文件时请从可信来源获取,以防恶意代码[^2]。 通过以上步骤,您应能解决 DevC++ 中无法使用 `bits/stdc++.h` 的问题。如果仍有疑问,请提供错误信息以便进一步诊断。 ### 相关问题 1. 如何检查 DevC++ 的编译器版本和安装路径? 2. 除了 DevC++,还有哪些 IDE(如 Visual Studio Code 或 Visual Studio)支持 `bits/stdc++.h` 头文件? 3. 使用 `bits/stdc++.h` 头文件有哪些优缺点?是否推荐在正式项目中使用? [^1]: 引用自站内关于万能头文件的描述。 [^2]: 引用自站内关于头文件放置方法的指导
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值