当前位置:   article > 正文

如何在Visual Studio编译C++时 使用万能头文件_visual怎么编译c++

visual怎么编译c++

如何在Visual Studio编译C++时 使用万能头文件

简单介绍下C++的万能头文件

当你不知道万能头写C++代码时

#include <iostream> 
#include <cstdio> 
#include <fstream> 
#include <algorithm> 
#include <cmath> 
#include <deque> 
#include <vector> 
#include <queue> 
#include <string> 
#include <cstring> 
#include <map> 
#include <stack> 
#include <set> 
using namespace std;
int main()
{    
    return 0;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18

然后 拥有了万能头之后的你写代码时

#include<bits/stdc++.h>
using namespace std;
int main()
{
    return 0;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

怎么说呢,哪个美观,简便,一眼就看得出。
因为#include<bits/stdc++.h>包含了目前c++所包含的所有头文件
<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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118

当然C++这个万能头文件也有他的缺点,它会降低编译速度(为何会降低编译速度,我还不能知道,等到之后学编译原理再来填坑吧)。
当然,私下自己想好好学习C++就不要去使用了,对你的自主学习一点都没有好处。(实力嘲讽我自己)
笔试平台可以使用,方便,VS中并不支持,一般G++ 4.4以上就支持这个头文件了,c++11支持这个。

如何在Visual Studio中使用万能头文件

一些小伙伴在安装了VS后(我安装的是2019),新建项目,
然后输入了一下代码

#include<bits/stdc++.h>
using namespace std;

int main() 
{
	cout << "hello world"<< endl;
	return 0;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

震惊!!竟然报错了!
很多轻量级IDE cb devcpp 包括vscode都支持万能头文件,但是vs没有,但是敲代码的时候敲一个万能头文件岂不是省下很多事
别慌,这么好用的万能头,在VS里怎么可以不用呢!
在捣鼓了半天,借鉴了多为大佬们的博客后,我成功让自己的VS可以正常使用万能头文件啦。

1.找到VS的安装路径

在这里插入图片描述

2.在VC文件夹里找到include

在这里插入图片描述
VC->Tools->MSVC->14.24.28314(此文件夹名每个人会有不同)->include

3.在include新建一个stdc++.h文件

在这里插入图片描述
然后把含有<bits/stdc++.h>的源代码的.h文件复制到bits文件夹中
(当然,如果你曾经安装过MinGW或者说什么其他编译器,dev cb等 是可以去安装的文件夹中找到bits文件夹的,然后复制即可)
然后 重启vs 之后 你再输入刚刚那段代码,就可以用啦!
在这里插入图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/运维做开发/article/detail/917650
推荐阅读
相关标签
  

闽ICP备14008679号