Can I use cstdio in a C program?

I am getting tons of errors in cstdio when I add #include <cstdio>

to 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 , so I am trying to include that.

+2


a source to share


3 answers


You want #include <stdio.h>

. cstdio

is a C ++ wrapper for the C header.

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



This site has a C implementation snprintf()

licensed under the GPL.

+7


a source


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



+1


a source


MSVC offers _snprintf

in stdio.h

.

If you prefer not to use the main 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).

+1


a source







All Articles