Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

C/C++²»¶¨²ÎÊýµÄÓ÷¨

C++²»¶¨²ÎÊýµÄÓ÷¨ £¨CÀàËÆ£©
2009-11-19 15:41
/*
va_list vl; //¶¨ÒåÒ»¸öÖ¸Ïò²ÎÊýÁбíµÄ±äÁ¿(Ò»¸ö...Ö¸Õë)
va_start(vl,first_param); //°ÑÖ¸Ïò²ÎÊýÁбíµÄ±äÁ¿³õʼ»¯
va_arg(vl,mode); //»ñÈ¡ÏÂÒ»¸ö²ÎÊý,²ÎÊýÀàÐÍÓɵڶþ¸ö²ÎÊýÖ¸¶¨,µÚ¶þ¸ö²ÎÊýÓÃÓÚÔÚva_argÄÚ²¿½øÐгߴç¼ÆËã,ÒÔ±ãÕÒµ½ÏÂÒ»¸ö²ÎÊý
va_end(vl); //½áÊø
*/
#include <iostream>
#include <cstdarg> //Í·Îļþ°üº¬:C++ <cstdarg>; C <stdarg.h>
using namespace std;
void variable(int i,...)
{
      int j=0;
      va_list arg_ptr; //¶¨ÒåÒ»¸öÖ¸Ïò²ÎÊýÁбíµÄ±äÁ¿
      va_start(arg_ptr,i); //°ÑÖ¸Ïò²ÎÊýÁбíµÄ±äÁ¿³õʼ»¯
      while(j!=-1) //×Ô¶¨ÒåµÄÒ»¸ö²ÎÊý½áÊø±êÖ¾
      {
             j=va_arg(arg_ptr,int); //»ñÈ¡ÏÂÒ»¸ö²ÎÊý
             printf("%d ",j);
      }
      va_end(arg_ptr); //½áÊø
}
int main()
{
      variable(3,3,4,5,6,-1);
      return 0;
}
Ò»¡¢Ê²Ã´Êǿɱä²ÎÊý
ÎÒÃÇÔÚCÓïÑÔ±à³ÌÖÐÓÐʱ»áÓöµ½Ò»Ð©²ÎÊý¸öÊý¿É±äµÄº¯Êý,ÀýÈçprintf()º¯Êý,Æ亯ÊýÔ­ÐÍΪ:
int printf( const char* format, ...);
Ëü³ýÁËÓÐÒ»¸ö²ÎÊýformat¹Ì¶¨ÒÔÍâ,ºóÃæ¸úµÄ²ÎÊýµÄ¸öÊýºÍÀàÐÍÊǿɱäµÄ£¨ÓÃÈý¸öµã"…"×ö²ÎÊýռλ·û£©,ʵ¼Êµ÷ÓÃʱ¿ÉÒÔÓÐÒÔϵÄÐÎʽ:
printf("%d",i);
printf("%s",s);
printf("the number is %d ,string is:%s", i, s);   
ÒÔÉÏÕâЩ¶«Î÷ÒÑΪ´ó¼ÒËùÊìϤ¡£µ«ÊǾ¿¾¹ÈçºÎд¿É±ä²ÎÊýµÄCº¯ÊýÒÔ¼°ÕâЩ¿É±ä²ÎÊýµÄº¯Êý±àÒëÆ÷ÊÇÈçºÎʵÏÖ£¬Õâ¸öÎÊÌâÈ´Ò»Ö±À§ÈÅÁËÎҺþᣱ¾ÎľÍÕâ¸öÎÊÌâ½øÐÐһЩ̽ÌÖ,Ï£ÍûÄܶԴó¼ÒÓÐЩ°ïÖú.
¶þ¡¢¿É±ä²ÎÊýÔÚ±àÒëÆ÷ÖеĴ¦Àí
ÎÒÃÇÖªµÀva_start,va_arg,va_end ÊÇÔÚstdarg.hÖỶ¨Òå³ÉºêµÄ, ÓÉÓÚ1)Ó²¼þƽ̨µÄ²»Í¬ 2)±àÒëÆ÷µÄ²»Í¬,ËùÒÔ¶¨ÒåµÄºêÒ²ÓÐËù²»Í¬,ÏÂÃæ¿´Ò»ÏÂVC++6.0ÖÐstdarg.hÀïµÄ´úÂ루ÎļþµÄ·¾¶ÎªVC°²×°Ä¿Â¼ÏµÄ\vc98 \include\stdarg.h£©
typedef char *     va_lis


Ïà¹ØÎĵµ£º

C/C++±à³Ì±Ø±¸

Windows C ³ÌÐòÉè¼ÆÈëÃÅÓëÌá¸ß
http://download.chinaitlab.com/program/files/13246.html
µ¥Æ¬»úCÓïÑÔÈëÃÅ
http://download.chinaitlab.com/program/files/12907.html
C++ ÈëÃÅ»ù´¡½Ì³Ì
http://download.chinaitlab.com/program/files/7617.html
CÓïÑÔ³£ÓÃËã·¨Ô´´úÂë
http://download.chinaitlab.com/program/files ......

¼òÊöCºÍC++³ÌÐòԱѧϰÀú³Ì

×ÜÊDZ»Í¬Ñ§ÃÇÎʵ½£¬ÈçºÎѧϰCºÍC++²Å²»Ã£È»£¬²Å²»ÊÇÂÒѧ£¬ÏëÁËһϣ¬ÕâÀï¸ø³öÒ»¸ö×ܵĻظ´¡£ 
¡¡¡¡Ò»¼ÒÖ®ÑÔ£¬»¶Ó­ÅÄש¹þ¡£ 
¡¡¡¡1¡¢¿ÉÒÔ¿¼ÂÇÏÈѧϰC. 
¡¡¡¡´ó¶àÊýʱºò£¬ÎÒÃÇѧϰÓïÑÔµÄÄ¿µÄ£¬²»ÊÇΪÁ˳ÉΪһ¸öÓïÑÔר¼Ò£¬¶øÊÇÏ£Íû³ÉΪһ¸ö½â¾öÎÊÌâµÄר¼Ò¡£×öÒ»¸öÓÐÓõijÌÐòÔ±£¬×öÒ»¸ö׬ǮµÄ³ÌÐòÔ±¡£ÎÒÃǵļ ......

CºÍC++Ö®¼äµÄ²»Í¬

£¨×¢£¬±¾ÎÄÊÇ·­ÒëµÄhttp://www.cprogramming.com/
ÉϵÄÎÄÕ Where C and C++ Differ
£©
C++»ùÓÚC£¬Ò²±£ÁôÁËCµÄ´ó²¿·ÖÌØÐÔ¡£µ«ÊÇÔÚÔ´Â뼶ÉÏÓÐЩµØ·½ÊÇÓëC²»¼æÈݵġ£
C³ÌÐòԱʹÓÃC++ʱµÄÏÝÚå
´Ó void* µÄÒþʽ·ÖÅä
²»ÄÜ´Ó void* ÒþʽµØ·ÖÅäµ½ÆäËûÈκÎÀàÐÍ¡£ÀýÈ磬ÏÂÃæµÄ´úÂëÔÚCÖÐÊǷdz£ÓÐЧµÄ¡£
    in ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ