0
点赞
收藏
分享

微信扫一扫

解决Vscode中万能头文件<bits/stdc++.h>不能使用的问题

由于博主最近由CB转到Vscode了,可是发现我最爱用的万能头文件​​<bits/stdc++.h>​​使用不了。于是我找了各种办法,终于解决了。为了帮助到同样遇到这样问题的你们,所以在这里列出详细解决方法。

首先,我们要知道问题根源所在,为什么引入​​iostream​​​可以,而引入​​bits/stdc++.h​​​不行,我们点击鼠标右键对这两个头文件转到定义。
解决Vscode中万能头文件<bits/stdc++.h>不能使用的问题_编辑器
发现尝试万能头文件的时候显示未定义,而尝试​​​isotream​​​的时候跳转到:
解决Vscode中万能头文件<bits/stdc++.h>不能使用的问题_#include_02
我们发现,这即是​​​iostream​​​头文件的定义,这里给出了它的路径。我们看看它在什么文件下。
解决Vscode中万能头文件<bits/stdc++.h>不能使用的问题_#include_03
右键选择在文件资源管理器中显示。我们看到如下:
解决Vscode中万能头文件<bits/stdc++.h>不能使用的问题_c++_04
这些都是好多头文件的定义,我们vscode引入头文件都是从这里寻找引入的。
那么我们试想,如果我们把​​​bits/stdc++.h​​​头文件的定义给出,是不是就可以引入了?在官网,有​​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

这里还有一个小细节,我们知道/(斜杆)其实代表目录的,也就是说​​stdc++.h​​​才是头文件名,它在​​bits​​​这个文件夹下的,所以我们要做的就是新建一个名为​​bits​​​的文件夹。然后在vscode中新建一个文件:​​stdc++.h​​​,将我们上面万能头文件的定义复制到该文件。保存在​​bits​​文件目录下即可。

我们测试helloworld程序,发现可以使用。问题解决。
解决Vscode中万能头文件<bits/stdc++.h>不能使用的问题_vscode_05


举报

相关推荐

0 条评论