【发布时间】:2012-01-03 17:32:03
【问题描述】:
我相信这是正确的标题:
#include <cstdio>
注意,上面的声明和这个有区别:
#include <stdio.h>
第一个将所有内容放在“std”命名空间中,第二个没有。所以我用的是第一个。
下面是我在 aix6.1 上使用 g++4.4.6 编译的代码:-
#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
这些是我得到的以下错误:-
virtual_utils.C: In function 'const char* VS::format_str(const char*, ...)':
virtual_utils.C:28: error: 'vsnprintf' is not a member of 'std'
编辑:
修改上述代码以删除#include "virtual_utils.h" 并添加main()、compiles with a warning under gcc4.3.4 on Ideone 和cleanly under gcc4.5.1。
【问题讨论】:
-
你确定 _MSC_VER 没有在任何地方定义?
-
@nos 它是 vsnprintf 而不是 _vsnprintf 并且 _MSC_VER 没有在任何地方定义。
-
std::vsnprintf在<cstdarg>,而不是<cstdio> -
@CharlesB : cplusplus.com/reference/clibrary/cstdarg 我没找到。再次检查。