VScode找不到C++万能头文件<bits/stdc++.h>解决办法

一、万能头文件介绍

万能头文件<bits/stdc++> 中包含了 C++中大部分头文件,在大部分做题平台、比赛当中都支持万能头文件的包含,这样以来可以减少编写头文件的工作量,节约做题时间,让选手更加专注于算法本身。但是在程序编写时不推荐使用,万能头文件不是C++标准的一部分,减少了代码的可移植性。

二、出现问题

  • 在使用VScode时发现万能头文件<bits/stdc++>的包含语句下出现红色波浪线。
    在这里插入图片描述

三、解决思路

  • 出现问题的原因:

    VScode不能在头文件的搜素路径中找到头文件。

  • 解决方案

    由于头文件中的语句只是一些文件包含语句,因此可以创建一个头文件,将其移动到系统的搜素路径下。

四、操作步骤 方法一

  • 首先输入能搜素到的头文件 < iostream >
#include<iostream>

在这里插入图片描述

  • 通过此头文件找到头文件目录

    • 选中 iostreamiostream ,右键转到定义
      在这里插入图片描述
  • 在 左侧右键点击 iostream 文件,在文件夹中显示
    在这里插入图片描述
    如果右边没显示这个文件的话,得手动到文件里找
    在这里插入图片描述
    在这里插入图片描述

  • 在桌面创建一个名为 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


在这里插入图片描述

  • 将保存好的头文件放入之前打开的include目录下(需要管理员权限)
    在这里插入图片描述
  • 这时候返回vscode,发现红色下划线消失了
    在这里插入图片描述

五、结果检测

用Hello word测试以下

#include <bits/stdc++.h>
using namespace std;
int main()
{
    cout << "Hello world\n";
    return 0;
}

在这里插入图片描述
万能头文件可以使用了!

六、操作步骤 方法二

  • 对于安装了vs2019却使用mingw的情况,这时vscode代码检测会默认使用vs2019的msvc编译器的头文件,如果你使用mingw独有的特殊头文件会报找不到头文件的错误。
    鼠标移动到报错头文件会显示一个灯泡,点击,选编辑"includePath"设置,然后在指定编译器下拉列表中选择gcc或者g++
    在这里插入图片描述
    在这里插入图片描述
    完成
  • 13
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 11
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 11
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值