16,547
社区成员




CLogFile logFile;
logFile.LOG_WriteLine(LOG_INFO_HIT,"Test= %f,%d", dTest, i);
void CLogFile::LOG_WriteLine(int nErrorLevel,const char* pFormatStr,...)
{
...
//分析输入可变参数.
va_list list;
va_start(list, pFormatStr);
vsprintf(Buf, pFormatStr, list); //一进入这里就报错
va_end(list);
....
}
// Test_arglist.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
void test( char * format, ... )
{
va_list args;
int len;
char *buffer;
// retrieve the variable arguments
va_start( args, format );
len = _vscprintf( format, args ) // _vscprintf doesn't count
+ 1; // terminating '\0'
buffer = (char*)malloc( len * sizeof(char) );
vsprintf( buffer, format, args ); // C4996
// Note: vsprintf is deprecated; consider using vsprintf_s instead
puts( buffer );
free( buffer );
}
int _tmain(int argc, _TCHAR* argv[])
{
test( "%d %c %d", 123, '<', 456 );
for (int i = 0; i < 100; i++)
{
test("Test= %0.2f,%012d", 5.333, i);
//logFile.LOG_WriteLine(LOG_INFO_HIT,"Test= Begin");
}
test( "%0.2f ", 5.333);
test( "%s", "This is a string" );
getchar();
return 0;
}