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++ vector造成的内存泄漏问题

    c++ vector造成的内存泄漏问题

    这篇文章主要介绍了c++ vector造成的内存泄漏问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教
    2023-08-08
  • C++中String增删查改模拟实现方法举例

    C++中String增删查改模拟实现方法举例

    这篇文章主要给大家介绍了关于C++中String增删查改模拟实现方法的相关资料,String是C++中的重要类型,程序员在C++面试中经常会遇到关于String的细节问题,甚至要求当场实现这个类,需要的朋友可以参考下
    2023-11-11
  • 使用c++实现OpenCV绘制圆端矩形

    使用c++实现OpenCV绘制圆端矩形

    这篇文章主要介绍了使用c++实现OpenCV绘制圆端矩形,其中着重的讲解了OpenCV使用过程中需要注意的一些小细节,避免浪费大家在开发过程中浪费多余的时间
    2021-08-08
  • C++零基础精通数据结构之带头双向循环链表

    C++零基础精通数据结构之带头双向循环链表

    带头双向循环链表:结构最复杂,一般用在单独存储数据。实际中使用的链表数据结构,都是带头双向循环链表。另外这个结构虽然结构复杂,但是使用代码实现以后会发现结构会带来很多优势,实现反而简单
    2022-03-03
  • Qt的QJsonObject存储QByteArray的方法实现

    Qt的QJsonObject存储QByteArray的方法实现

    本文主要介绍了Qt的QJsonObject存储QByteArray的方法实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2026-02-02
  • visual studio 2022中的scanf问题解决

    visual studio 2022中的scanf问题解决

    昨天在使用Visual Studio 2022编写C语言程序时遇到了scanf问题,对于vs的编译器来说scanf是不安全的,编译器通过不了scanf,本文就来介绍一下解决方法,感兴趣的可以了解一下
    2023-12-12
  • C++实现LeetCode(126.词语阶梯之二)

    C++实现LeetCode(126.词语阶梯之二)

    这篇文章主要介绍了C++实现LeetCode(126.词语阶梯之二),本篇文章通过简要的案例,讲解了该项技术的了解与使用,以下就是详细内容,需要的朋友可以参考下
    2021-07-07
  • C语言常用库函数的使用及模拟实现详解例举

    C语言常用库函数的使用及模拟实现详解例举

    C语言库函数是把自定义函数放到库里,是别人把一些常用到的函数编完放到一个文件里,供程序员使用,下面让我们一起来详细了解它
    2022-04-04
  • C++中基类和派生类之间的转换实例教程

    C++中基类和派生类之间的转换实例教程

    这篇文章主要介绍了C++中基类和派生类之间的转换,有助于深入理解C++面向对象程序设计,需要的朋友可以参考下
    2014-08-08
  • C++ Strassen算法代码的实现

    C++ Strassen算法代码的实现

    这篇文章主要介绍了C++ Strassen算法代码的实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2020-03-03

最新评论