[ÖØÒª]CÖÐfread()º¯ÊýµÄ·µ»ØÖµ
×î½üÓиöÏîÄ¿ÐèÒªÔÚUNIXÏÂÓÃC×ö£¬ºÜ¾ÃûÓùýCÁË£¬·¢ÏÖЩÎÊÌâÈÝÒ׸ã´í¡£
Õâ¸öÎÊÌâºÜÈÝÒ׸ã´í£¬²¢µ¼ÖºܶàÎÊÌ⣬ÐèҪǿµ÷µÄÊÇfreadº¯Êý·µ»ØµÄ²¢²»ÊÇ×Ö½ÚÊý¡£
realRead = fread(buf,item,count,fp) £¨Ã¿´Î¶Áitem´óСµÄÊý¾Ý¿é£¬·Öcount´ÎÀ´¶Á¡££©
¶øÊÇ·µ»ØµÄÊdzɹ¦ÓÐЧµÄ¶ÁÈ¡µÄitemÔªËصĸöÊý£¬¶ø³É¹¦¶ÁÈëµÄ×Ö½ÚÊýÔòÊÇrealRead * sizeof(item)
Ò»°ã˵À´realRead ÊÇСÓÚcountµÄ£¬ºÜÇɵÄÇé¿ö¾Í¸ÕºÃΪcount.³ý·ÇÎļþ´óС¸ÕºÃΪitem´óСµÄÕûÊý±¶¡£
·µ»ØµÄÊÇÕæʵ¶ÁÈëitemÔªËصĸöÊý£¬ËäÈ»¶ÁÁËcount´Î£¬µ«ÊÇÕæÕý¶Áµ½µÄÓÐЧ¸öÊýΪrealRead¸ö
Õæʵ¶ÁÈë×Ö½ÚÊý¾ÍΪrealRead*sizeof(item)
RETURN VALUE
fread and fwrite return the number of items successfully read or written (i.e., not the number of
characters). If an error occurs, or the end-of-file is reached, the return value is a short item
count (or zero).
fread does not distinguish between end-of-file and error, and callers must use feof(3) and ferror(3)
to determine which occurred.
fread£¨´ÓÎļþÁ÷¶ÁÈ¡Êý¾Ý£©
±íÍ·Îļþ #include<stdio.h>
¶¨Ò庯Êý size_t fread(void * ptr,size_t size,size_t count,FILE * stream);
º¯Êý˵Ã÷ fread()ÓÃÀ´´ÓÎļþÁ÷ÖжÁÈ¡Êý¾Ý¡£²ÎÊýstreamΪÒÑ´ò¿ªµÄÎļþÖ¸Õ룬²ÎÊýptr Ö¸ÏòÓû´æ·Å¶ÁÈ¡½øÀ´µÄÊý¾Ý¿Õ¼ä£¬¶ÁÈ¡µÄ×Ö½ÚÊýÒÔ²ÎÊýsize*countÀ´¾ö¶¨¡£
Fread()»á·µ»Øʵ¼Ê¶ÁÈ¡µ½µÄcountÊýÄ¿£¬Èç¹û´ËÖµ±È²ÎÊýcountÀ´µÃС£¬Ôò´ú±í¿ÉÄܶÁµ½ÁËÎļþβÁË»òÕßÓдíÎó·¢Éú(Ç°Õß¼¸ÂÊ´ó)£¬Õâʱ±ØÐëÓÃfeof()»òferror()À´¾ö¶¨·¢ÉúʲôÇé¿ö¡£
·µ»ØÖµ ·µ»Øʵ¼Ê¶ÁÈ¡µ½µÄcountÊýÄ¿¡£
fread·µ»ØµÄ²»ÊÇ×Ö½ÚÊý£¬
µ±ÇÒ½öµ±ÏÂÃæÕâôÓõÄʱºò£¬·µ»ØÖµ²ÅÊÇ×Ö½ÚÊý£¨µ±È»ÒòΪǡºÃÒ»¸öÊý¾Ý¿é´óСΪ1¸ö×Ö½Ú£¬Ï൱ÓÚrealRead*1£©
char buff[size];
FILE *fp;
...
realRead = fread(buff, 1, size, fp);
...
Èç¹ûÊÇ: fread(buff, size, 1, fp)
·
Ïà¹ØÎĵµ£º
ͨÓú¯Êý¿âÔÚÍ·Îļþstdlib.hÖÐÉùÃ÷£¬±È½ÏÅÓ´ó£¬Ö÷Òª·ÖΪÒÔϼ¸´óÀࣺ´æ´¢·ÖÅä¡¢Ëæ»úÊýÉú³É¡¢Êý×Öת»»ÓëÕûÐÍÔËËã¡¢³ÌÐòÍ˳öÓë»·¾³Í¨ÐÅ¡¢ËÑË÷ÓëÅÅÐò¡¢¶à×Ö½ÚÓë¿í×Ö·ûµÄת»»¡£ÓÉÓÚ¼³¼°µ½´æ´¢·ÖÅä¡¢»·¾³Í¨Ðŵȣ¬Òò´ËËüÃǵĴó¶àÊýÒ²ÒÀÀµÓÚ²Ù×÷ϵͳ¡£glibcÖУ¬Í¨Óú¯Êý¿âµÄºËÐÄʵÏÖÔÚstdlibºÍmallocÁ½¸öĿ¼Ï ......
»ùÓÚÓÅÏȼ¶µÄ²Ù×÷ϵͳ£¨preemptive operating system£©±ØÐëʹÓÃijÖÖËã·¨ÒÔ¾ö¶¨CPUÈçºÎµ÷¶ÈϵͳÖеÄỊ̈߳¬±¾Õ½«ÌÖÂÛWindows VistaʹÓõĵ÷¶ÈËã·¨¡£ ÎÒÃÇ֮ǰÌÖÂÛ¹ýÏ̵߳ÄÉÏÏÂÎĽṹCONTEXT£¬ÆäÖк¬ÓÐÏß³Ì×îºóÒ»´ÎÖ´ÐÐʱCPU¼Ä´æÆ÷×éµÄ״̬¡£ ²Ù×÷ϵͳÿ20ºÁÃë¼ì²éϵͳÖÐËùÓÐÏß³ÌÄں˶ÔÏóµÄ״̬£¬ÆäÖÐһЩ¶ÔÏó±»ÈÏΪÊǿɵ÷¶È£ ......
/¼ÓÁËÏÂÃæÁ½¸öÍ·Îļþ£¬ÊÇΪÁËÔÚWin32¹¤³ÌÖÐʹÓÃMFCµÄÌØÐÔ!
#include <afx.h>
#include <afxwin.h>
#include "stdio.h"
#include "conio.h"
////¼ÓÁËÏÂÃæÁ½¾ä£¬ÊÇΪÁËÄܹ»ÓÃstring(basic_stringÀàÐÍ)
#include <string>
using namespace std;
int main(int argc, char* argv[ ......
Ôø¾ÈÏΪ£¬Ñ§ºÃCÓïÑÔ´ò±éÌìÏÂÎÞµÐÊÖ¡£ ºóÀ´·¢ÏÖΪÁËÃæÏò¶ÔÏ󣬲»µÃ²»ÓÃC++£¬ºóÀ´·¢ÏÖÃæÏò¶ÔÏó¹ûÈ»ÊǷdz£Î°´óµÄ˼Ï룡 ÔÙºóÀ´£¬´ÓVS6.0Õâ¸ö°æ±¾Ö®ºó£¬VC¾ÍÒѾûÓÐʲô̫´óµÄ±ä»¯ÁË£¬MFCµÈµÈ¶¼ÒѾÎȶ¨ÏÂÀ´ÁË£¬Î¢Èí²»ÍæÁË£¬Î¢ÈíÅܵ½.netƽ̨ÉÏÃæÈ¥ÍæÁË£¡£¡Î¢ÈíһЩеÄÓ¦Óã¬È«²¿¶¼Åܵ½.netƽ̨ÉÏÈ¥ÁË£¬VCƽ̨¸öÈ˾õµÃ¾ÍÊ£ ......
±àÕß°´:·Ç³£»ù±¾¹ØÓÚCÓïÑÔµÄÎÊÌâ,Ò»¸öÐÅÏ¢Àà(¼ÆËã»ú,×ÊѶ¹¤³Ì,µç×Ó¹¤³Ì, ͨÐÅ
¹¤³Ì)רҵµÄ±¾¿Æ±ÏÒµÉúÓ¦¸Ã´ïµ½µÄˮƽ¡£ÌâÄ¿²»ÄÑ,È«²¿¶¼ÄÜ¿ìËٵشðÍ꣬µ±È»Ò²ÐèÒª
Ò»¶¨µÄ֪ʶ´¢±¸¡£
¶ÔÓÚ´ó¶àÊýÈË£¬ÎÒÃÇÔ¤ÆÚÄã¿ÉÄÜ´ð´í 1) 4) 15)Ì⣬ËùÒÔ´ð´í3µÀÒÔÄڵģ¬ÎÒÃÇÈÏΪ
ÄãºÜ°ô
´ð´í5µÀÌâÒÔ ......