C++常见头文件汇总

这篇具有很好参考价值的文章主要介绍了C++常见头文件汇总。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

目录

一.<iostream>(input&output stream)

二.<stdio.h>(standard buffered input&output)

三.<bit/stdc++.h>

四.<algorithm>

五. <cmath>和<math.h>


一.<iostream>(input&output stream)

#include <iostream>
  1. iostream分为istream和ostream,istream(输入流)类型,提供输入操作;ostream(输出流)类型,提供输出操作。
  2. 输入流 " cin>> " 和 输出流 " cout<< " ,后面接的数据类型可以是int,float,double,string等。
  3. 但是输入输出时必须标注空间域,可以在cout语句前面加上"std::cout",也可以在开头表明"using namespace std;"

在C++中,std是标准库(Standard Library)的命名空间(namespace)。但在大型项目中,为了避免命名冲突,一般建议显式地使用"std::"前缀,而不采用"using namespace std;"的方式。

二.<stdio.h>(standard buffered input&output)

#include <stdio.h>
  1. 标准输入输出函数,也提供输入输出的功能。
  2. 在C++中,优先使用"<iostream>"来代替"<stdio.h>","<stdio.h>"主要用于C风格的输入输出。如"printf"和"scanf"进行格式化输入输出。

三.<bits/stdc++.h>

#include <bits/c++std.h>
  1. 俗称万用头,意思就是啥都有,使得开发者不需要逐个包含各个便准库头文件,但是带来的弊端也很明显,那就是大大延长的编译的时间,使得项目得效率降低。
  2. 经常被用于竞赛,避免重复写一些库文件,但并不是所有的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>
  1. <algorithm>是C++标准模板库中algorithm头文件,它包含了一些算法,如sort(排序)、max(最大值)、min(最小值)、swap(交换)等。
  2. 由于是标准模板库文件,使用时同样也需要标注空间域,即使用"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语言中没有的额外功能,如函数模板、异常处理等。

本文将不断更新C++其他的头文件,如有错误欢迎指出文章来源地址https://www.toymoban.com/news/detail-705409.html

到了这里,关于C++常见头文件汇总的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包赞助服务器费用

相关文章

  • C++面试高频问题汇总( 一)

    参考: 作者:小王同学在积累 链接:https://www.zhihu.com/question/440248845/answer/1698042313 作者:二进制架构 链接:https://www.zhihu.com/people/binarch/posts?page=2 struct和class有什么区别 在C++中,struct和class的唯一区别是默认的访问控制。 struct 默认的成员是 public 的,而 class 的默认成员是

    2024年02月21日
    浏览(12)
  • 八皇后问题汇总(C++版)

    八皇后问题汇总(C++版)

    八皇后问题(英文:Eight queens),是由国际象棋棋手马克斯·贝瑟尔于1848年提出的问题,是回溯算法的典型案例。 问题表述为:在8×8格的国际象棋上摆放8个皇后,使其不能互相攻击,即任意两个皇后都不能处于同一行、同一列或同一斜线上,问有多少种摆法。高斯认为有

    2024年02月16日
    浏览(2)
  • C++——string容器常用操作汇总

    C++——string容器常用操作汇总

    纵有疾风起,人生不言弃。本文篇幅较长,如有错误请不吝赐教,感谢支持。 C语言风格字符串(以空字符结尾的字符数组)太过复杂难于掌握,不适合大程序的开发,所以C++标准库定义了一种string类,定义在头文件。 string容器可以看做一片连续的储存空间,并用一个char*指向这

    2024年02月13日
    浏览(11)
  • C++ 遇到问题汇总及解决方案

    C++ 遇到问题汇总及解决方案

    (1)错误信息 LNK1169 找到一个或多个多重定义的符号,如下图所示: (2)原因 多个文件中都包含main函数,main函数是程序启动入囗,出现多个时,程序不知道先启动哪个。 (3)解决方案 3.1、右键单击 不要运行的 C++源文件 - 选择“属性” 注意是不要运行的源文件 ,将在

    2024年02月05日
    浏览(13)
  • C++软件分析工具案例分析集锦汇总

    本文是 C++常用软件分析工具从入门到精通案例集锦 专栏的导航贴( 点击链接,跳转到专栏主页,欢迎订阅,持续更新… )。 专栏介绍 :根据近几年C++软件异常排查的项目实践,详细地讲述如何使用PE工具、Dependency Walker、GDIView、Process Explorer、Process Monitor、API Monitor、Clum

    2024年02月11日
    浏览(13)
  • C++ Http Server 开源库(汇总级整理)

    C++ Http Server 开源库(汇总级整理)

    C++ http server 开源框架 ⚠️ 最新版本请参考:https://ericpengshuai.github.io/c-c/039eca2b3cfe.html star 统计截止至 2022.12.10 名称 说明 链接 star cpp-httplib A C++ header-only HTTP/HTTPS server and client library https://github.com/yhirose/cpp-httplib 8.2k incubator-brpc 百度开源的 RPC 框架,比较详细的中文文档 https

    2023年04月22日
    浏览(13)
  • OpenCV [c++](图像处理基础示例程序汇总)

    OpenCV [c++](图像处理基础示例程序汇总)

    目录 一、图像读取与显示 二、图像预处理[高斯滤波、canny边缘检测、膨胀腐蚀] Canny边缘检测 三、图像裁剪  四、绘制形状和添加文本  五、透视投影变换矫正  六、颜色检测  七、形状检测和轮廓检测[findContours(),approxPolyDP()]   八、人脸识别 九、虚拟画笔作画 十、文档扫

    2024年02月04日
    浏览(15)
  • C++设计模式(23种)汇总及代码实现

    目录 设计模式七大原则: 开闭原则: 单一职责原则: 里氏替换原则: 依赖倒转原则: 接口隔离原则: 迪米特原则(最少知道原则): 合成复用原则: 三大模式及其特点: 创建型模式: 结构型模式: 行为模式: --------------------我是一个分界线,接下来是创造型模式---

    2024年04月15日
    浏览(89)
  • C++中将数字转换成string的方法汇总

    在C++中,将数字转换成字符串的方法有多种,以下是一些常用的方法: std::to_string()函数 : 使用C++标准库中的  std::to_string()  函数,可以将整数、浮点数以及其他数字类型转换为字符串,如前面的示例所示。 使用字符串流(std::ostringstream) : 可以使用  std::ostringstream  类

    2024年02月08日
    浏览(13)
  • 剑指offer:关于二叉树的汇总(c++)

    剑指offer:关于二叉树的汇总(c++)

    1、重建二叉树: 输入某二叉树的前序遍历和中序遍历的结果,请重建出该二叉树。假设输入的前序遍历和中序遍历的结果中都不含重复的数字。例如输入前序遍历序列{1,2,4,7,3,5,6,8}和中序遍历序列{4,7,2,1,5,3,8,6},则重建二叉树并返回。 2、树的子结构: 输入两棵二叉树A和B,

    2023年04月12日
    浏览(9)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包