C ++ - 无法使用g ++(Ubuntu 4.8.5-4ubuntu6)在ubuntu17.10上编译<cstdio>的函数

时间:2018-03-01 12:28:58

标签: c++ ubuntu gcc g++

我是这个论坛的新手,并提出以下问题。 我最近安装了ubuntu 17.10(巧妙)。我的编译器是g ++(Ubuntu 4.8.5-4ubuntu6 (g ++的输出--version)。不幸的是,由于我使用的特定框架,我无法选择更新的编译器版本。我写了以下最小的例子:

//test.cpp
#include <cstdio>
int main ()
{
  char buffer [100];
  int cx;

  cx = std::snprintf ( buffer, 100, "The dhalf of %d is %d", 60, 60/2 );


 }

当我尝试通过

编译时
g++  -std=gnu++11 -o test test.cpp

我收到以下编译错误:

test.cpp: In function ‘int main()’:
test.cpp:8:13: error: ‘snprintf’ is not a member of ‘std’
    cx = std::snprintf ( buffer, 100, "The half of %d is %d", 60, 60/2 );
         ^
test.cpp:8:13: note: suggested alternative:
In file included from /usr/include/c++/4.8/cstdio:42:0,
             from test2.cpp:1:
/usr/include/stdio.h:340:12: note:   ‘snprintf’
extern int snprintf (char *__restrict __s, size_t __maxlen,

有人知道为什么会这样吗?提前谢谢!

0 个答案:

没有答案