Can I use cstdio in a C program?

2019-07-16 05:13发布

I get a ton of errors in cstdio when I add #include <cstdio> to the C program.

c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(17) : error C2143: syntax error : missing '{' before ':'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(17) : error C2059: syntax error : ':'

Thanks

EDIT - I would like to use snprintf, which is why I am trying to include this.

标签: c include
3条回答
该账号已被封号
2楼-- · 2019-07-16 05:50

You want #include <stdio.h>. cstdio is the C++ wrapper for the C header.

Edit: MSVC only supports the elements in C99 that form a subset of C++.

This site has a C implementation of snprintf() licensed under the GPL.

查看更多
虎瘦雄心在
3楼-- · 2019-07-16 06:05

With Visual Studio, I believe you have to use sprintf_s or something similar. See this. There's also vsnprintf.

查看更多
劫难
4楼-- · 2019-07-16 06:05

MSVC offers the _snprintf function in stdio.h.

If you prefer not to use the leading underscore, you can:

#include <stdio.h>
#define snprintf _snprintf

This is a C library function, not specifically related to C++ (although you can use it there too).

查看更多
登录 后发表回答