C++無法打開源文件bits/stdc++.h的問題
VS 是不支持 萬能頭的,需要我們自己去手動(dòng)添加。
原理
首先我們得知道萬能頭是個(gè)啥東西。(其實(shí)是我不知道。。QAQ)<bits/stdc++.h> 其實(shí)就是一個(gè)頭文件,里面包含了幾乎所有的C++庫里的頭文件。
因此一般只需要包含這一個(gè)頭文件就能滿足所有的需求。
不過自然也會(huì)有著一些缺點(diǎn)。
優(yōu)點(diǎn)
- 簡(jiǎn)單便捷。能滿足大多數(shù)場(chǎng)合,即一些對(duì)運(yùn)行需求不大嚴(yán)格的場(chǎng)合。
- 節(jié)省時(shí)間,不必考慮需要加入哪些頭文件。這對(duì)參與競(jìng)賽的時(shí)候能起到一點(diǎn)幫助。
缺點(diǎn)
- 包含所有的頭文件,編譯時(shí)速度自然就稍慢一些,增加編譯時(shí)間。
- 這不是C++的標(biāo)準(zhǔn)庫,因而不是所有的編譯系統(tǒng)都有,比如一些OJ就可能沒有。
- 不建議新手使用,新手還是要多用用庫文件,才知道那些標(biāo)準(zhǔn)庫里都有啥。
VS添加<bits/stdc++.h>
首先我們需要新建一個(gè)文件夾bits,然后創(chuàng)建一個(gè)頭文件stdc++.h。
頭文件內(nèi)容即是萬能頭里的實(shí)質(zhì)內(nèi)容。
文件內(nèi)容
// 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_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
隨后我們需要將這個(gè)文件夾加入到VS的環(huán)境變量中,為了便于頭文件的管理,此處我們把這個(gè)文件夾跟VS其余頭文件放到一起。
便捷操作
首先輸入#include<iostream>。
右鍵 – 打開文檔

右鍵 – 打開文件所在位置

復(fù)制文件夾進(jìn)去即可。

其中的路徑大家可以參考下。
至此就完成了。
總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
C++基礎(chǔ)知識(shí)之運(yùn)算符重載詳解
這篇文章主要為大家詳細(xì)介紹了C++基礎(chǔ)知識(shí)之運(yùn)算符重載,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來幫助2022-02-02
單鏈表實(shí)現(xiàn)反轉(zhuǎn)的3種方法示例代碼
單鏈表的反轉(zhuǎn)是常見的面試題目,下面這篇文章主要給大家介紹了關(guān)于單鏈表實(shí)現(xiàn)反轉(zhuǎn)的3種方法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧2019-02-02
C語言深入探究水仙花數(shù)與變種水仙花數(shù)代碼
求水仙花數(shù)和變種水仙花數(shù)是非常適合初學(xué)者學(xué)習(xí)的代碼,其中包含的循環(huán)和邏輯方式等知識(shí)點(diǎn)。這既能起到對(duì)以往知識(shí)的復(fù)習(xí),也可以學(xué)習(xí)到一種不同的邏輯思考方式2022-05-05
使用VS2019編譯CEF2623項(xiàng)目的libcef_dll_wrapper.lib的方法
這篇文章主要介紹了使用VS2019編譯CEF2623項(xiàng)目的libcef_dll_wrapper.lib的方法,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-04-04
c++臨時(shí)對(duì)象導(dǎo)致的生命周期問題
對(duì)象的生命周期是c++中非常重要的概念,它直接決定了你的程序是否正確以及是否存在安全問題,這篇文章主要介紹了c++臨時(shí)對(duì)象導(dǎo)致的生命周期問題 ,需要的朋友可以參考下2024-07-07
C++中繼承與多態(tài)的基礎(chǔ)虛函數(shù)類詳解
這篇文章主要給大家介紹了關(guān)于C++中繼承與多態(tài)的基礎(chǔ)虛函數(shù)類的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。2017-09-09

