C++ 无法打开 源 文件「bits/stdc++.h」

本文介绍了在Visual Studio(VS)中遇到无法打开源文件「bits/stdc++.h」的问题及其解决方法。尽管此万能头文件不被官方支持且存在编译慢等缺点,但它为程序员提供了简洁的途径来包含大量C++库。解决步骤包括手动创建头文件并将其添加到VS的环境变量中,以实现便捷的使用。
摘要由CSDN通过智能技术生成

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_ASSER
评论 13
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值