c – 为什么编译此代码会产生错误?
发布时间:2020-12-16 06:58:01 所属栏目:百科 来源:网络整理
导读:我相信这是正确的标题: #include cstdio 请注意,上述声明与此声明之间存在差异: #include stdio.h 第一个将所有内容放在“std”命名空间中,第二个放在“std”命名空间中.所以我使用第一个. 下面是我在aix6.1上使用g 4.4.6编译的代码: – #include cstdarg
我相信这是正确的标题:
#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' 编辑: 解决方法
使用–save-temps编译,并检查它生成的.ii文件.这应该清楚说明在什么命名空间中定义了什么,什么不是.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |