【Windows环境下】VS Code中引用"bits/stdc++.h"头文件时出现“无法打开 源 文件"bits/stdc++.h"”错误的解决方法

【推荐】最近刷题时发现了一个“万能头文件”:<bits/stdc++.h>,它包含了全部标准库的c++头文件,只需要敲上一个#include<bits/stdc++.h>,便可省去敲各种需要头文件(如等等)的时间。

【含义】:bits文件夹下的stdc++.h头文件(standard c++)

【位置】最早我使用的IDE是Dev-C++,因此在我的安装目录下的MinGW集中就有一个现成的stdc++.h(这个路径基本上只有CDEF盘和版本号(4.9.2)的区别)
D:\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\x86_64-w64-mingw32\bits
顺便附上stdc++.h的内容:

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

当然,没有的话也没关系,找到bits文件夹后在其中新建一个txt文档,然后将上述内容Crtl+c,Crtl+v进去,最后命名为stdc++.h,保存就OK啦

【新问题出现】上午刷题刷得好好的,过了一个中午突然就“无法打开 源 文件"bits/stdc++.h"”。。什么鬼。还加空格嘲讽我不知道源文件是什么东西??一通百度之后发现大家都是这么干的:“将bits文件夹中的内容复制粘贴到vsc的头文件库里/vsc对应的头文件文件夹中”,wtf?百度vsc头文件库。。null,后来突然反应过来,我是要修改头文件,所以这里的头文件库/头文件文件夹应该是指的vsc缺省的头文件库(即没有c_cpp_properties.json文件的情况下的默认编译器)
我的机器中目前版本的vsc的缺省路径是:
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.25.28610\include
果然在这其中并没有bits文件夹,将上面整个bits文件夹(只复制粘贴一个stdc++.h也是不起作用的)粘贴过来后,重启vsc,问题解决。

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值