C语言中各种Include的文件及作用是什么?

C语言中各种Include的文件及作用是什么?,第1张

#include <assert.h>//设定插入点

#include <ctype.h>//字符处理

#include <errno.h>//定义错误码

#include <float.h>//浮点数处理

#include <fstream.h>  //文件输入/输出

#include <iomanip.h>  //参数化输入/输出

#include <iostream.h> //数据流输入/输出

#include <limits.h>//定义各种数据类型最值常量

#include <locale.h>//定义本地化函数

#include <math.h> //定义数学函数

#include <stdio.h>//定义输入/输出函数

#include <stdlib.h>//定义杂项函数及内存分配函数

#include <string.h>//字符串处理

#include <strstrea.h> //基于数组的输入/输出

#include <time.h> //定义关于时间的函数

#include <wchar.h>//宽字符处理及输入/输出

#include <wctype.h>//宽字符分类

include在C语言中表示文件包含,属于编译预处理。

如:

在C盘根目录下有文件1.txt,里面内容为:

fun()

{ return 1}

自己建立C语言程序,如:

#include "c:\\1.txt"

main()

{

printf("%d",fun())

}

程序在编译时,将会用1.TXT中文件的内容代替#include "c:\\1.txt",相当于C语言程序就编程了:

fun()

{ return 1}

main()

{

printf("%d",fun())

}

输出结果就为1.

分类: 电脑/网络 >>程序设计 >>其他编程语言

解析:

#include "stdio.h"

#include "math.h"

main()

{

double x,s

printf("input number:\n")

scanf("%lf",&x)

s=sin(x)

printf("sine of %lf is %lf\n",x,s)

}

预处理命令还有其它几种,这里的include 称为文件包含命令,其意义是把尖括号""或引号<>内指定的文件包含到本程序来,成为本程序的一部分。被包含的文件通常是由系统提供的,其扩展名为.h。因此也称为头文件或首部文件。C语言的头文件中包括了各个标准库函数的函数原型。因此,凡是在程序中调用一个库函数时,都必须包含该函数原型所在的头文件。在本例中,使用了三个库函数:输入函数scanf,正弦函数sin,输出函数printf。sin函数是数学函数,其头文件为math.h文件,因此在程序的主函数前用include命令包含了math.h。scanf和printf是标准输入输出函数,其头文件为stdio.h,在主函数前也用include命令包含了stdio.h文件。


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/tougao/11474595.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-16
下一篇 2023-05-16

发表评论

登录后才能评论

评论列表(0条)

保存