C++无法打开源文件bits/stdc++.h的问题

 更新时间:2023年08月04日 10:12:48   作者:Lv.Twelve.  
这篇文章主要介绍了C++无法打开源文件bits/stdc++.h的问题以及解决方案,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教

VS 是不支持 万能头的,需要我们自己去手动添加。

原理

首先我们得知道万能头是个啥东西。(其实是我不知道。。QAQ)<bits/stdc++.h> 其实就是一个头文件,里面包含了几乎所有的C++库里的头文件

因此一般只需要包含这一个头文件就能满足所有的需求

不过自然也会有着一些缺点。

优点

  • 简单便捷。能满足大多数场合,即一些对运行需求不大严格的场合。
  • 节省时间,不必考虑需要加入哪些头文件。这对参与竞赛的时候能起到一点帮助。

缺点

  • 包含所有的头文件,编译时速度自然就稍慢一些,增加编译时间。
  • 这不是C++的标准库,因而不是所有的编译系统都有,比如一些OJ就可能没有。
  • 不建议新手使用,新手还是要多用用库文件,才知道那些标准库里都有啥。

VS添加<bits/stdc++.h>

首先我们需要新建一个文件夹bits,然后创建一个头文件stdc++.h

头文件内容即是万能头里的实质内容

文件内容

// C++ includes used for precompiling -*- C++ -*-
// Copyright (C) 2003-2017 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

随后我们需要将这个文件夹加入到VS的环境变量中,为了便于头文件的管理,此处我们把这个文件夹跟VS其余头文件放到一起。

便捷操作

首先输入#include<iostream>

右键 – 打开文档

右键 – 打开文件所在位置

复制文件夹进去即可。

其中的路径大家可以参考下。

至此就完成了。

总结

以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。

相关文章

  • C/C++经典算法之约瑟夫问题详解

    C/C++经典算法之约瑟夫问题详解

    这篇文章主要给大家介绍了关于C/C++经典算法之约瑟夫问题的相关资料,约瑟夫环问题是一道经典的数据结构的题目,本文介绍了解决约瑟夫问题的三种方法,需要的朋友可以参考下
    2021-07-07
  • C++基础知识之运算符重载详解

    C++基础知识之运算符重载详解

    这篇文章主要为大家详细介绍了C++基础知识之运算符重载,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下,希望能够给你带来帮助
    2022-02-02
  • 单链表实现反转的3种方法示例代码

    单链表实现反转的3种方法示例代码

    单链表的反转是常见的面试题目,下面这篇文章主要给大家介绍了关于单链表实现反转的3种方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面来一起学习学习吧
    2019-02-02
  • C语言深入探究水仙花数与变种水仙花数代码

    C语言深入探究水仙花数与变种水仙花数代码

    求水仙花数和变种水仙花数是非常适合初学者学习的代码,其中包含的循环和逻辑方式等知识点。这既能起到对以往知识的复习,也可以学习到一种不同的逻辑思考方式
    2022-05-05
  • 使用VS2019编译CEF2623项目的libcef_dll_wrapper.lib的方法

    使用VS2019编译CEF2623项目的libcef_dll_wrapper.lib的方法

    这篇文章主要介绍了使用VS2019编译CEF2623项目的libcef_dll_wrapper.lib的方法,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2020-04-04
  • c++临时对象导致的生命周期问题

    c++临时对象导致的生命周期问题

    对象的生命周期是c++中非常重要的概念,它直接决定了你的程序是否正确以及是否存在安全问题,这篇文章主要介绍了c++临时对象导致的生命周期问题 ,需要的朋友可以参考下
    2024-07-07
  • C++中继承与多态的基础虚函数类详解

    C++中继承与多态的基础虚函数类详解

    这篇文章主要给大家介绍了关于C++中继承与多态的基础虚函数类的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧。
    2017-09-09
  • C语言实现三角函数表

    C语言实现三角函数表

    这篇文章主要为大家详细介绍了C语言三角函数表,打印出相对应的三角函数值,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2019-06-06
  • C++实现多人聊天室

    C++实现多人聊天室

    这篇文章主要为大家详细介绍了C++实现多人聊天室,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2021-06-06
  • C++实现链表版本通讯录

    C++实现链表版本通讯录

    这篇文章主要为大家详细介绍了C++实现链表版本通讯录,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2019-12-12

最新评论