This works:
#include <iostream> using namespace std; but this fails:
#include <stdio> When is .h not needed?
About the namespace issue,I didn't find such logic in cstdio:
#pragma once #ifndef _CSTDIO_ #define _CSTDIO_ #include <yvals.h> #ifdef _STD_USING #undef _STD_USING #include <stdio.h> #define _STD_USING #else /* _STD_USING */ #include <stdio.h> #endif /* _STD_USING */ // undef common macro overrides #undef clearerr #undef feof #undef ferror #undef getc #undef getchar #undef putc #undef putchar #define _HAS_CONVENTIONAL_CLIB 1 #define _IOBASE _base #define _IOPTR _ptr #define _IOCNT _cnt #ifndef _FPOSOFF #define _FPOSOFF(fp) ((long)(fp)) #endif /* _FPOSOFF */ typedef FILE _Filet; #ifndef RC_INVOKED #if _GLOBAL_USING _STD_BEGIN using ::_Filet; using ::size_t; using ::fpos_t; using ::FILE; using ::clearerr; using ::fclose; using ::feof; using ::ferror; using ::fflush; using ::fgetc; using ::fgetpos; using ::fgets; using ::fopen; using ::fprintf; using ::fputc; using ::fputs; using ::fread; using ::freopen; using ::fscanf; using ::fseek; using ::fsetpos; using ::ftell; using ::fwrite; using ::getc; using ::getchar; using ::gets; using ::perror; using ::putc; using ::putchar; using ::printf; using ::puts; using ::remove; using ::rename; using ::rewind; using ::scanf; using ::setbuf; using ::setvbuf; using ::sprintf; using ::sscanf; using ::tmpfile; using ::tmpnam; using ::ungetc; using ::vfprintf; using ::vprintf; using ::vsprintf; _STD_END #endif /* _GLOBAL_USING */ #endif /* RC_INVOKED */ #endif /* _CSTDIO_ */
_STD_BEGINand_STD_ENDfor the namespace declaration.stdio.h?usingstatements between_STD_BEGINand_STD_ENDimport those names into the std namespace. They would now be available both assize_tandstd::size_t(don't ask me why they should be kept visible globally). - The C++ versions have other differences. For example, it appears that some things are macros in C libraries, which C++ redefines as normal functions. Also,<cmath>adds various overloads to functions (no overloading in C) etc.