#include#includevoidDisplayMsg(char*msg);intmain()
{char*cp=0;
DisplayMsg(cp);return0;
}voidDisplayMsg(char*msg)
{
assert(msg!=0);
std::cout<
}
2、头文件
头文件中声明的函数用于转换字符变量并测试其是否在给定范围之内。int isdigit(int c);
当c是数字(0~9)返回真
int isupper(int c);
当c是大写字母(A~Z)时返回真
int islower(int c);
当c是小写字母(a~z)时返回真
int isalpha(int c);
当c是字母(a~z,A~Z)时返回真
int isalnum(int c);
与isalpha(c)一样
int isprint(int c);
当c是可显示的ASCII字符时返回真
int isspace(int c);
当c是空字符时返回真
int toupper(int c);
c的大写形式
int to lower(int c);
c的小写形式
#include#includeusingnamespacestd;intmain()
{chara='a',A='A',num='2',s='';chara1,A1;if(isdigit(num))
cout<
cout<
cout<
cout<
cout<
cout<
cout<
a1=tolower(A);
cout<
A1=toupper(a);
cout<
}
3、头文件double(double x);撒地方
头文件中声明了标准数学函数。double acos(double x);
x的反余弦
double asin(double x);
x的反正弦
double atan(double x);
x的反正切
double atan2(double y,double x);
y/x的反正切
double ceil(double x);
不小于x的最小整数
double cos(double x);
x的余弦
double cosh(double x);
x的双曲余弦
double exp(double x);
e的x次方
double fabs(double x);
x的绝对值
double floor(double x);
不大于x的最大整数
double log(double x);
x的自然对数
double log10(double x);
x的以10为底的对数
double pow(double x,double y);
x的y次方
double sin(double x);
x的正弦
double sinh(double x);
x的双曲正弦
double sqrt(double x);
x的平方根
double tan(double x);
x的正切
double tanh(double x);
x的双曲正切
#includeusingnamespacestd;
#includeintmain()
{doublex=0,y=1,
acos1=acos(x),
asin1=asin(x),
atan1=atan(x),
atan21=atan2(x,y),
cos1=cos(x),
sin1=sin(x),
tan1=tan(x),
cosh1=cosh(x),
sinh1=sinh(x),
tanh1=tanh(x),
log1=log(y),
log101=log10(y),
exp1=exp(x),
pow1=pow(y,x);doublenum=-3.25,
ceil1=ceil(num),
fabs1=fabs(num),
floor1=floor(num),
sqrt1=sqrt(num);
cout<
cout<
cout<
cout<
cout<
cout<
cout<
cout<
cout<
cout<
cout<
cout<
cout<
cout<
cout<
cout<
cout<
cout<
}
4、头文件
头文件声明了支持标准输入输出的函数和全局符号。支持控制台以及文件输入/输出。也定义了NULL——一个表示控指针的全局符号。
5、头文件
头文件声明了很多标准函数和宏,分为4大类:数字函数、内存管理函数、系统函数和随机数发生器函数
1)数字函数int abs(int i);
i的绝对值
int atoi(const char *s);
字符串代表的整形值
long atol(const char *s);
字符串代表的长整形值
float atof( const char *s);
字符串代表的浮点型值
2)内存管理函数
void *calloc(int sz,int n);
void *malloc(int sz);
void free(void *buf);
malloc和calloc的区别:第一,malloc要求以字符数目给出所需内存的大小,而calloc则要求以每一项的大小和项的数目给出所需内存的大小;第二,calloc把已分配内存的内容全部初始化为0,而malloc则不进行初始化。
3)系统函数
系统函数有三个:void abort();void exit(int n);int system(const char *cmd);
abort和exit函数用于终止程序的运行。abort函数使程序异常终止。exit函数是程序正常终止,它将关闭所有打开的流文件,并将传递给它的参数返回给操作系统。
system函数调用操作系统来执行一个操作系统命令。
#includeintmain()
{
std::system("dir *.doc");return0;
}
4)随机数发生器函数
相关函数有:int rand(); void srand(unsigned int seed);
#include#include#includeintmain()
{
srand(time(0));charans;do{intfav=rand()%32;intnum;do{
std::cout<
std::cin>>num;
std::cout<
num>fav?"Too high":"Right")<<:endl>
}while(num!=fav);
std::cout<
std::cin>>ans;
}while(ans=='y');return0;
}
6、头文件
头文件声明了用于处理以零值结尾的字符型数组的函数,其中两个比较函数、两个复制函数、两个串联函数、一个计算字符串长度函数和一个用指定字符填充内存区域的函数。
int strcmp(const char *s1,const char *s2);
int strncmp(const char *s1,const char *s2,int n);
char *strcpy(char *s1,const char *s2);
char *strncpy(char *s1,const char *s2,int n);
int strlen(const char *s);
char *strcat(char *s1,const char *s2);
char *strncat(char *s1,const char *s2,int n);
char *memset(void *s,int c,int n);
#include#includeintmain()
{intlen;charmsg[]="Wrong.";
std::cout<
std::cin>>pwd;
len=strlen(pwd);if(strcmp(pwd,"boobah")==0)
strcpy(msg,"OK.");
std::cout<
}
7、文件头
头文件声明了喝操作时间、日期相关的一些函数、一个结构和一个数据类型。
struct tm {
int tm_sec; /* seconds after the minute - [0,59] */
int tm_min; /* minutes after the hour - [0,59] */
int tm_hour; /* hours since midnight - [0,23] */
int tm_mday; /* day of the month - [1,31] */
int tm_mon; /* months since January - [0,11] */
int tm_year; /* years since 1900 */
int tm_wday; /* days since Sunday - [0,6] */
int tm_yday; /* days since January 1 - [0,365] */
int tm_isdst; /* daylight savings time flag */
};
相关函数:
char *asctime(const struct tm *time);
char *ctime(const time_t *t);
double difftime(time_t t1,time_t t2);
struct tm *gmtime(const time_t *t);
struct tm *localtime(const time_t *t);
time_t mktime(struct tm * time);
time_t time(time_t *t);
#include#includeintmain()
{
time_t now=time(0);
std::cout<
}
posted on 2009-06-21 19:51 The_Moment 阅读(1289) 评论(0) 编辑 收藏 引用 所属分类: C\C++

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/77943.html