目录
一.<iostream>(input&output stream)
二.<stdio.h>(standard buffered input&output)
三.<bit/stdc++.h>
四.<algorithm>
五. <cmath>和<math.h>
一.<iostream>(input&output stream)
#include <iostream>
- iostream分为istream和ostream,istream(输入流)类型,提供输入操作;ostream(输出流)类型,提供输出操作。
- 输入流 " cin>> " 和 输出流 " cout<< " ,后面接的数据类型可以是int,float,double,string等。
- 但是输入输出时必须标注空间域,可以在cout语句前面加上"std::cout",也可以在开头表明"using namespace std;"
在C++中,std是标准库(Standard Library)的命名空间(namespace)。但在大型项目中,为了避免命名冲突,一般建议显式地使用"std::"前缀,而不采用"using namespace std;"的方式。
二.<stdio.h>(standard buffered input&output)
#include <stdio.h>
- 标准输入输出函数,也提供输入输出的功能。
-
在C++中,优先使用"<iostream>"来代替"<stdio.h>","<stdio.h>"主要用于C风格的输入输出。如"printf"和"scanf"进行格式化输入输出。
三.<bits/stdc++.h>
#include <bits/c++std.h>
- 俗称万用头,意思就是啥都有,使得开发者不需要逐个包含各个便准库头文件,但是带来的弊端也很明显,那就是大大延长的编译的时间,使得项目得效率降低。
- 经常被用于竞赛,避免重复写一些库文件,但并不是所有的oj平台都支持该库文件。
库的具体内容:
// C++ includes used for precompiling -*- C++ -*-
// Copyright (C) 2003-2013 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
// <Licenses - GNU Project - Free Software Foundation>.
/** @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
四.<algorithm>
#include <algorithm>
- <algorithm>是C++标准模板库中algorithm头文件,它包含了一些算法,如sort(排序)、max(最大值)、min(最小值)、swap(交换)等。
- 由于是标准模板库文件,使用时同样也需要标注空间域,即使用"std"命名空间
五.<cmath> 和 <math.h>
#include <cmath>
#include <math.h>
<cmath>和<math.h>
是C++和C语言中用于数学计算的标准库头文件。它们提供了一系列数学函数和常量,可以进行数值计算和数学操作,常见的如求绝对值函数,取整运算,幂运算,三角函数等等。
区别:
- 命名空间:
<cmath>
中的数学函数和常量位于std
命名空间中,而<math.h>
中的函数和常量不属于任何命名空间。在C++中,使用<cmath>
时需要使用std::
前缀,如std::sin
;而在C语言中,使用<math.h>
时直接使用函数名,如sin
-
兼容性:
<cmath>
是C++标准库中的头文件,而<math.h>
是C语言标准库中的头文件。因此,<cmath>
中的函数和常量在C++中是可用的,而<math.h>
中的函数和常量在C和C++中都是可用的。 -
类型安全:
<cmath>
中的函数和常量使用了函数重载和模板,提供了类型安全的数学计算。它们可以处理不同类型的参数,如浮点数、整数等,并返回相应的结果类型。而<math.h>
中的函数通常只接受和返回double
类型的参数和结果。 -
扩展功能:由于C++具有更多的语言特性和面向对象的设计,
<cmath>
中可能会提供一些C语言中没有的额外功能,如函数模板、异常处理等。文章来源:https://www.toymoban.com/news/detail-705409.html
本文将不断更新C++其他的头文件,如有错误欢迎指出文章来源地址https://www.toymoban.com/news/detail-705409.html
到了这里,关于C++常见头文件汇总的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!