我相信这是正确的标题:为什么编译此代码会产生错误?
#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一个nd cleanly under gcc4.5.1。
你确定_MSC_VER没有在任何地方定义? – nos
@nos它是vsnprintf而不是_vsnprintf,_MSC_VER没有在任何地方定义。 –
'std :: vsnprintf'在''而不是'' –
CharlesB