VC函数库详解Word文档下载推荐.docx

上传人:b****1 文档编号:5230662 上传时间:2023-05-04 格式:DOCX 页数:169 大小:65.93KB
下载 相关 举报
VC函数库详解Word文档下载推荐.docx_第1页
第1页 / 共169页
VC函数库详解Word文档下载推荐.docx_第2页
第2页 / 共169页
VC函数库详解Word文档下载推荐.docx_第3页
第3页 / 共169页
VC函数库详解Word文档下载推荐.docx_第4页
第4页 / 共169页
VC函数库详解Word文档下载推荐.docx_第5页
第5页 / 共169页
VC函数库详解Word文档下载推荐.docx_第6页
第6页 / 共169页
VC函数库详解Word文档下载推荐.docx_第7页
第7页 / 共169页
VC函数库详解Word文档下载推荐.docx_第8页
第8页 / 共169页
VC函数库详解Word文档下载推荐.docx_第9页
第9页 / 共169页
VC函数库详解Word文档下载推荐.docx_第10页
第10页 / 共169页
VC函数库详解Word文档下载推荐.docx_第11页
第11页 / 共169页
VC函数库详解Word文档下载推荐.docx_第12页
第12页 / 共169页
VC函数库详解Word文档下载推荐.docx_第13页
第13页 / 共169页
VC函数库详解Word文档下载推荐.docx_第14页
第14页 / 共169页
VC函数库详解Word文档下载推荐.docx_第15页
第15页 / 共169页
VC函数库详解Word文档下载推荐.docx_第16页
第16页 / 共169页
VC函数库详解Word文档下载推荐.docx_第17页
第17页 / 共169页
VC函数库详解Word文档下载推荐.docx_第18页
第18页 / 共169页
VC函数库详解Word文档下载推荐.docx_第19页
第19页 / 共169页
VC函数库详解Word文档下载推荐.docx_第20页
第20页 / 共169页
亲,该文档总共169页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

VC函数库详解Word文档下载推荐.docx

《VC函数库详解Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《VC函数库详解Word文档下载推荐.docx(169页珍藏版)》请在冰点文库上搜索。

VC函数库详解Word文档下载推荐.docx

_atoi64

把一个字符串转换为_int64型

__int64_atoi64(constchar*string);

和atof函数类似

_beginthread

process.h>

创建一个线程

unsignedlong_beginthread(void(__cdecl*start_address)(void*),unsignedstack_size,void*arglist);

unsignedlong_beginthreadex(

这个例子显示了_beginthread函数的基本用法,FirstThread是线程的起始地址,数字20是线程的堆栈空间,常量NULL是线程的参数表:

_beginthread(FirstThread,20,NULL);

_beginthreadex

unsignedlong_beginthreadex(void*security,unsignedstack_size,unsigned(__stdcall*start_address)(void*),void*arglist,unsignedinitflag,unsigned*thrdaddr);

和_beginthread函数类似

_c_exit

进行清除操作(释放已占用的内存空间等),但是不终止程序

void_c_exit(void);

和_cexit函数类似

_cabs

math.h>

计算一个复数的绝对值

double_cabs(struct_complexz);

把一个复数ComplexNumber赋给变量d:

struct_complexnumber={3.0,4.0};

doubled;

d=_cabs(number);

_cexit

void_cexit(void);

这个例子中如果用户按下y键,则进行清除操作:

intbutton;

_cputs("

YesorNo?

"

);

button=_getch();

if(toupper(button)=='

y'

)_cexit();

_cgets

conio.h>

从键盘得到一个字符串

char*_cgets(char*buffer);

数字80用来限制屏幕上每行最多只能输入80个字符:

char*string;

charBuffer[82]={80};

string=_cgets(Buffer);

_chdir

direct.h>

改变当前的工作目录,若成功则返回0,否则返回-1,

int_chdir(constchar*dirname);

这个例子中实现了把当前目录改为d:

\visualc++:

_chdir("

d;

\\visualc++"

_chdrive

改变当前的工作驱动器

int_chdrive(intdrive);

这个例子中实现了检查计算机中有多少个可用的驱动器(PC机最多可以装26个驱动器):

intDrive=1;

while(Drive<

=26){if(_chdrive(Drive)==0)printf("

%c\n"

Drive+'

A'

-1);

Drive++;

}

_chgsign

float.h>

改变一个double型数的正负号(正变为负,负变为正)

double_chgsign(doublex);

给double型变量x赋值为-12345.678:

doublex;

x=_chgsign(12345.678);

_chmod

改变文件的读写许可设置,如果改变成功返回0,否则返回-1

int_chmod(constchar*filename,intpmode);

这个例子中实现了把文件sample.txt设置为只读文件:

if(_chmod("

sample.txt"

_S_IREAD)==-1)cout<

<

文件sample.txt不存在"

;

elsecout<

文件sample.txt变为只读文件"

_chsize

改变文件的字节长度,如果成功返回0,否则返回-1

int_chsize(inthandle,longsize);

和_chmod函数类似

_clear87

返回并且清除浮点状态字

unsignedint_clear87(void);

这个例子中变量x是float型的,把一个double型的值赋给它时可能会引起数据的溢出,这个时候我们使用_clear87函数来检查溢出的情况:

floatx;

doubley=1.4e-35;

x=y;

printf("

浮点状态字%x代表数据的溢出\n"

_clear87());

_clearfp

unsignedint_clearfp(void);

和_clear87函数类似

_close

关闭文件,如果成功返回0,否则返回-1

int_close(inthandle);

这个例子中先以只读方式打开文件sample.txt,然后再把它关闭:

intHandle;

Handle=_open("

c:

\\sanmple.txt"

_O_RDONLY);

if(Handle==-1)perror("

出错!

else{cout<

文件已经打开"

_close(Handle);

}

_commit

把某个文件的数据直接存储到磁盘上,如果成功返回0,否则返回-1

int_commit(inthandle);

这个例子中可以把文件的数据在操作中及时写入磁盘,可以避免一些以外情况导致文件的数据丢失:

if((Handle=_open("

_O_RDWR))!

=-1){......_commit(Handle);

......_close(Handle);

_control87

返回或者设置浮点控制字

unsignedint_control87(unsignedintnew,unsignedintmask);

_control87函数可以控制浮点类型数据的精度:

doubleValue=0.1;

_control87(_PC_24,MCW_PC);

24位精度:

%f\n"

Value);

_control87(_CW_DEFAULT,0xFFFFF);

缺省精度:

_controlfp

unsignedint_controlfp(unsignedintnew,unsignedintmask);

和_control87函数类似

_copysign

以第二个参数y的符号(正或负)返回第一个参数x

double_copysign(doublex,doubley);

这个例子中变量a的值为-0.4567:

doublex=0.4567;

doubley=-0.123;

doublea;

a=_copysign(x,y);

_cprintf

用指定的格式在显示器上输出信息

int_cprintf(constchar*format[,argument]...);

intI=-16,h=29;

unsignedu=62511;

charc='

chars[]="

Test"

_cprintf("

%d%.4x%u%c%s\r\n"

I,h,u,c,s);

_cputs

在显示器上输出一个字符串,若成功则返回0,否则返回一个非0值

int_cputs(constchar*string);

这个例子中实现了在显示器上显示“hello!

”:

char*p="

hello!

_cputs(p);

_creat

创建一个新的文件,若成功返回0,否则返回-1

int_creat(constchar*filename,intpmode);

这个例子中实现了创建一个新文件sample.txt:

Handle=_creat("

_S_IREAD|_S_IWRITE);

_cscanf

从键盘上输入已经指定格式的数据

int_cscanf(constchar*format[,argument]...);

这个例子中%d就是格式控制:

intx;

_csanf("

%d"

&

x);

_cwait

某个进程开始进入等待状态直到另一个进程终止为止

int_cwait(int*termstat,intprocHandle,intaction);

这个例子中若变量x为2将显示两个carl:

structprocess{intid;

charname[40];

}process[3]={{0,"

ann"

},{0,"

beth"

carl"

}};

voidmain(intargc,char*argv[]){intindex,result;

if(argc==1){for(index=0;

index<

3;

index++)process[index].id=_spawnl(_P_

_dup

为一个已经打开的文件建立第二个句柄

int_dup(inthandle);

这个例子中给已经有句柄的标准输出设备(stdout)建立第二个句柄Monitor,然后再恢复原来的句柄:

intMonitor;

Monitor=_dup

(1);

......_dup2(Monitor,1);

_dup2

为一个文件重新分配句柄

int_dup2(inthandle1,inthandle2);

请参看_dup函数

_ecvt

把一个double型的数据转换为一个字符串

char*_ecvt(doublevalue,intcount,int*dec,int*sign);

这个例子中变量Prcision存储数字的精度,变量Decimal存储小数点的位置,变量Sign存储数字的符号:

char*String;

doubleValue=2.143554;

intPrecision=10,Decimal,Sign;

String=_ecvt(Value,Precision,&

Decimal,&

sign);

_endthread

终止_beginthread函数创建的某个线程

void_endthread(void);

请参看_beginthread函数

_endthreadex

void_endthreadex(unsignedretval);

和_endthread函数类似

_eof

测试文件指针是否指向文件尾部,若指向文件尾部返回0,否则返回-1

int_eof(inthandle);

这个例子中打开文件eof.c,每次读取10个字节,直到全部字节被读完为止,然后显示文件的长度:

voidmain(void){

intfh,count,total=0;

charbuf[10];

if((fh=_open("

eof.c"

_O_RDONLY))==-1){perror("

Openfailed"

exit

(1);

}while(!

_eof(fh)){if((count=_read(f

_execl

在父进程中装载并执行新的子进程,若成功则返回0,否则返回-1

int_execl(constchar*cmdname,constchar*arg0,...Constchar*argn,NULL);

这个例子介绍了以_exec开头的8个函数的用法:

char*my_env[]={"

THIS=environmentwillbe"

"

PASSED=tonewprocessby"

theEXEC=functions"

NULL};

voidmain(){char*args[4],prog[80];

intch;

printf("

Enternameofprogramtoexec:

"

gets(prog

_execle

int_execle(constchar*cmdname,constchar*arg0,...Constchar*argn,NULL,constchar*const*envp);

请参看_execl函数

_execlp

int_execlp(constchar*cmdname,constchar*arg0,...Constchar*argn,NULL);

_execlpe

int_execlpe(constchar*cmdname,constchar*arg0,...Constchar*argn,NULL,constchar*const*envp);

_execv

int_execv(constchar*cmdname,constchar*const*argv);

_execve

int_execve(constchar*cmdname,constchar*const*argv,constchar*const*envp);

_execvp

int_execvp(constchar*cmdname,constchar*const*argv);

_execvpe

int_execvpe(constchar*cmdname,constchar*const*argv,constchar*const*envp);

_exit

or<

进行清除操作(释放已占用的内存空间等),并且终止当前进程

void_exit(intstatus);

和exit函数类似

_expand

改变某个内存区域的字节数

void*_expand(void*memblock,size_tsize);

这个例子中把buffer从512个字节扩展到了1024个字节:

char*buffer;

buffer=(char*)calloc(512,sizeof(char));

cout<

内存区域为512个字节!

endl;

buffer=(char*)_expand(buffer,1024);

内存区域为1024个字节!

free(buffer);

_fcloseall

关闭已经打开的所有数据流,若成功则返回被关闭的数据流的个数,否则返回eof

int_fcloseall(void);

和fclose函数类似

_fcvt

char*_fcvt(doublevalue,intcount,int*dec,int*sign);

和_ecvt函数类似

_fdopen

把一个以低级I/O方式打开的文件与某个数据流联系起来,即将这个文件“数据流化”,若成功则返回一个指向该数据流的指针,否则返回NULL

FILE*_fdopen(inthandle,constchar*mode);

这个例子中先以句柄方式打开文件sample.txt,然后以数据流的方式处理该文件:

  inthandle,line=0;

FILE*stream;

charbuffer[120];

handle=_open("

steam=_fdopen(handle,"

r"

while(fgets(buffer,120,stream)!

=NULL)line++;

fclose(stream);

文件中有"

l

_fgetchar

从标准输入设备上读取一个字符

int_fgetchar(void);

和fgetc函数类似

_fgetwchar

wchar.h>

从标准输入设备读取一个字符

wint_t_fgetw

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > PPT模板 > 商务科技

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2