版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/w442863748/article/details/50731552
#include "stdafx.h"
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <math.h>
#include <vector>
#include <sstream>
#include <list>
#include <algorithm>
#include <time.h>
#include <stdarg.h>
#include "myLibrary.h"
//头文件引用的较多,有一些和本程序无关
using namespace std;
int sum(int num, ...)
{
va_list ap;
va_start(ap, num);
int sum = 0;
while(num-- > 0)
{
sum += va_arg(ap, int);
//cout << va_arg(ap, int) << endl;
}
va_end(ap);
return sum;
}
int main(int argc, char *argv[])
{
cout << sum(3, 1, 2, 3) << endl;
system("pause");
return 0;
}
执行结果: