c fopenº¯Êý
[CÓïÑÔ]fopen()º¯ÊýµÄ²ÎÊý˵Ã÷
2007Äê06ÔÂ05ÈÕ ÐÇÆÚ¶þ 23:55
¸ñʽ£ºÎļþÖ¸ÕëÃû=fopen(ÎļþÃû£¬Ê¹ÓÃÎļþ·½Ê½)
²ÎÊý£º
ÎļþÃû ÒâÒå
"C:/temp/temp.txt" Îļþ C:\temp\temp.txt
ÎļþʹÓ÷½Ê½ ¡¡ Òâ Òå
“rt”¡¡¡¡¡¡¡¡¡¡Ö»¶Á´ò¿ªÒ»¸öÎı¾Îļþ£¬Ö»ÔÊÐí¶ÁÊý¾Ý
“wt”¡¡¡¡¡¡¡¡ ֻд´ò¿ª»ò½¨Á¢Ò»¸öÎı¾Îļþ£¬Ö»ÔÊÐíдÊý¾Ý
“at”¡¡¡¡¡¡¡¡ ×·¼Ó´ò¿ªÒ»¸öÎı¾Îļþ£¬²¢ÔÚÎļþĩβдÊý¾Ý
“rb”¡¡¡¡¡¡¡¡ Ö»¶Á´ò¿ªÒ»¸ö¶þ½øÖÆÎļþ£¬Ö»ÔÊÐí¶ÁÊý¾Ý
“wb”¡¡¡¡¡¡¡¡ ֻд´ò¿ª»ò½¨Á¢Ò»¸ö¶þ½øÖÆÎļþ£¬Ö»ÔÊÐíдÊý¾Ý
“ab” ¡¡¡¡¡¡¡¡×·¼Ó´ò¿ªÒ»¸ö¶þ½øÖÆÎļþ£¬²¢ÔÚÎļþĩβдÊý¾Ý
“rt+”¡¡¡¡¡¡¡¡¶Áд´ò¿ªÒ»¸öÎı¾Îļþ£¬ÔÊÐí¶ÁºÍд¡£ÓÃfseekÈ·¶¨¶ÁдλÖã¬Ð´¶àÉÙ¸²¸Ç¶àÉÙ£¬
ºóÃæµÄÄÚÈݱ£Áô¡£ÒòΪ´ÅÅÌ¿Õ¼äÊÇÁ¬ÐøµÄ£¬ËùÒÔÄã²»ÄÜÔÚÖмä²åÈ룬ÔÚÖмäÒ»µ©
дÈë¾ÍÊǸ²¸ÇÓëдÈëÄÚÈݵȳ¤µÄÄÇЩÄÚÈÝ¡£
“wt+”¡¡¡¡¡¡¡¡¶Áд´ò¿ª»ò½¨Á¢Ò»¸öÎı¾Îļþ£¬ÔÊÐí¶Áд
“at+”¡¡¡¡¡¡¡¡¶Áд´ò¿ªÒ»¸öÎı¾Îļþ£¬ÔÊÐí¶Á£¬»òÔÚÎļþĩ׷¼ÓÊý¾Ý
“rb+”¡¡¡¡¡¡¡¡¶Áд´ò¿ªÒ»¸ö¶þ½øÖÆÎļþ£¬ÔÊÐí¶ÁºÍд
“wb+”¡¡¡¡¡¡¡¡¶Áд´ò¿ª»ò½¨Á¢Ò»¸ö¶þ½øÖÆÎļþ£¬ÔÊÐí¶ÁºÍд
“ab+” ¡¡¡¡¡¡¡¡¶Áд´ò¿ªÒ»¸ö¶þ½øÖÆÎļþ£¬ÔÊÐí¶Á£¬»òÔÚÎļþĩ׷¼ÓÊý¾Ý
¶ÔÓÚÎļþʹÓ÷½Ê½ÓÐÒÔϼ¸µã˵Ã÷£º
¡¡¡¡1. ÎļþʹÓ÷½Ê½ÓÉr,w,a,t,b£¬+Áù¸ö×Ö·ûÆ´³É£¬¸÷×Ö·ûµÄº¬ÒåÊÇ£º
¡¡¡¡r(read): ¶Á
¡¡¡¡w(write): д
¡¡¡¡a(append): ×·¼Ó
¡¡¡¡t(text): Îı¾Îļþ£¬¿ÉÊ¡ÂÔ²»Ð´
¡¡¡¡b(banary): ¶þ½øÖÆÎļþ
¡¡¡¡+: ¶ÁºÍд
¡¡¡¡2. ·²ÓÓr”´ò¿ªÒ»¸öÎļþʱ£¬¸ÃÎļþ±ØÐëÒѾ´æÔÚ£¬ÇÒÖ»ÄÜ´Ó¸ÃÎļþ¶Á³ö¡£
¡¡¡¡3. ÓÓw”´ò¿ªµÄÎļþÖ»ÄÜÏò¸ÃÎļþдÈë¡£Èô´ò¿ªµÄÎļþ²»´æÔÚ£¬ÔòÒÔÖ¸¶¨µÄÎļþÃû½¨Á¢¸ÃÎļþ£¬Èô´ò¿ªµÄÎļþÒѾ´æÔÚ£¬Ôò½«¸ÃÎļþɾȥ£¬Öؽ¨Ò»¸öÐÂÎļþ¡£
¡¡¡¡4. ÈôÒªÏòÒ»¸öÒ
Ïà¹ØÎĵµ£º
## Á¬½Ó·ûÓë# ·û
¡¡¡¡## Á¬½Ó·ûºÅÓÉÁ½¸ö¾®ºÅ×é³É£¬Æ书ÄÜÊÇÔÚ´ø²ÎÊýµÄºê¶¨ÒåÖн«Á½¸ö×Ó´®(token)Áª½ÓÆðÀ´£¬´Ó¶øÐγÉÒ»¸öеÄ×Ó´®¡£µ«Ëü²»¿ÉÒÔÊǵÚÒ»¸ö»òÕß×îºóÒ»¸ö×Ó´®¡£ËùνµÄ×Ó´®(token)¾ÍÊÇÖ¸±àÒëÆ÷Äܹ»Ê¶±ðµÄ×îСÓï·¨µ¥Ôª¡£¾ßÌåµÄ¶¨ÒåÔÚ±àÒëÔÀíÀïÓÐÏ꾡µÄ½âÊÍ£¬µ«²»ÖªµÀÒ²ÎÞËùν¡£Í¬Ê±ÖµµÃ×¢ÒâµÄÊÇ#Á¬½Ó·ûÊÇ°Ñ´«µÝ¹ý ......
¼òÊö
Ò» ÁÐÎļþÇåµ¥
¶þ£ºÖ´ÐгÌÐò
Èý£ºÏÔʾÊý¾Ý
ËÄ£º¶Ïµã(breakpoint)
Î壮¶ÏµãµÄ¹ÜÀí
Áù£®±äÁ¿µÄ¼ì²éºÍ¸³Öµ
Æß. µ¥²½Ö´ÐÐ
°Ë£®º¯ÊýµÄµ÷ÓÃ
&nb ......
ÍøÓѹ۵ã:
(Ò»):
ÎÒÈÏΪºÜ¶àÈËûÓÐÀí½âlinus»òÕßmyanµÄÒâ˼£¬ÎÒ¾Ù¸öʵÀý¡£
ÎÒÃÇÏÖÔÚÒªÉè¼ÆÒ»Ì×ÍøÂ磿ͻ§¶ËÈí¼þ£¬ÎÒÃÇÒªÏÈ°ÑÐÒ鶨ºÃ£¬°Ñ½çÃæºÍºǫ́½»»¥Éè¼ÆÏëºÃ£¬°ÑÈÝ´íºÍ»Ö¸´ÏëºÃ£¬ÎÒÈÏΪÕâЩÊÇ×îÖØÒªµÄ£¬ÖÁÓÚ±àÂ룬ÓÃCÒ²¿ÉÒÔ±à³öÀ´£¬ÓÃC£«£«Ò²¿ÉÒÔ±à³öÀ´£¬ÉõÖÁÓÃJAVAÒ²Äܱà³öÀ´£¬¹Ø¼üÊÇÕû¸öÈí¼þµÄ¼Ü¹¹ÒªÇåÎú£¬Õ ......
1.MFCÖеķ½·¨£º(C++) CFileStatus status;
CFile::GetStatus("D:\\test.txt",status);
long lSizeOfFile;
lSizeOfFile = status.m_size; lSizeOfFileµÄÖµ¾ÍÊÇD:\\test.txtÎļþµÄ´óС 2.±ê×¼C»ñµÃÎļþ´óСµÄ5ÖÖ·½·¨
(×¢Ò⣺"__FILE__"Ö¸µÄÊǵ±Ç°Îļþ£¬Äã¿ÉÒÔ¸ÄΪÓÐЧ·¾¶µÄÄ¿±êÎļþ£¬±ÈÈç"D:\\test.tx ......