I believe this is the correct header:
#include <cstdio>
Please note that there is a difference between the above declaration and this:
#include <stdio.h>
The first puts everything in the "std" namespace, and the second does not. Therefore, I use the first one.
Below is the code that I am compiling with g ++ 4.4.6 on aix6.1: -
#include <cstdarg> //< va_list #include <cstdio> //< vsnprintf() #include "virtual_utils.h" namespace VS { const char* format_str( const char* str, ... ) throw() { static char buf[10][1024]; static unsigned long buf_no = 0; char* cur_buf = buf[ ++buf_no % 10 ]; buf_no %= 10; va_list vl; va_start( vl, str ); #ifdef _MSC_VER std::_vsnprintf( cur_buf, sizeof(buf), str, vl ); #else std::vsnprintf( cur_buf, sizeof(buf), str, vl ); #endif return cur_buf; } } //< namespace VS
These are the following errors that I get: -
virtual_utils.C: In function 'const char* VS::format_str(const char*, ...)': virtual_utils.C:28: error: 'vsnprintf' is not a member of 'std'
Edit: By changing the above code to remove #include "virtual_utils.h"
and add main()
, it compiles with a warning in gcc4.3.4 to Ideone and purely under gcc4.5.1 .
source share