由于博主最近由CB转到Vscode了,可是发现我最爱用的万能头文件<bits/stdc++.h>
使用不了。于是我找了各种办法,终于解决了。为了帮助到同样遇到这样问题的你们,所以在这里列出详细解决方法。
首先,我们要知道问题根源所在,为什么引入iostream
可以,而引入bits/stdc++.h
不行,我们点击鼠标右键对这两个头文件转到定义。
发现尝试万能头文件的时候显示未定义,而尝试isotream
的时候跳转到:
我们发现,这即是iostream
头文件的定义,这里给出了它的路径。我们看看它在什么文件下。
右键选择在文件资源管理器中显示。我们看到如下:
这些都是好多头文件的定义,我们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
// C++
这里还有一个小细节,我们知道/(斜杆)其实代表目录的,也就是说stdc++.h
才是头文件名,它在bits
这个文件夹下的,所以我们要做的就是新建一个名为bits
的文件夹。然后在vscode中新建一个文件:stdc++.h
,将我们上面万能头文件的定义复制到该文件。保存在bits
文件目录下即可。
我们测试helloworld程序,发现可以使用。问题解决。