我相信这是正确的标题:
#include <cstdio>
请注意,上述声明与此声明之间存在差异:
#include <stdio.h>
第一个将所有内容放在“std”命名空间中,第二个放在“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,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.
解决方法
使用–save-temps编译,并检查它生成的.ii文件.这应该清楚说明在什么命名空间中定义了什么,什么不是.