In versions earlier than VC ++ 4.1, the library used is called the run-time library, and the header file names are all "*. H ". Standard C ++ Library (Standard C ++ Library) has been used since VC ++ 4.2. The standard C ++ library complies with ANSI standards, it enables your program to be transplanted between different compilation systems and platforms. The new header file name does not have the ". H" extension, but the standard C ++ library still retains 18 C header files with the ". H" extension.
In the program, you can select to use the old header file (". H "format header file), you can also use the new Standard C ++ library header file (header file without extension file name ). During the connection, the compilation system automatically determines the database to be connected Based on the header file name.
The content in the C: \... \ vc98 \ include \ cstdio file is as follows:
// Cstdio Standard Header
# If _ msc_ver> 1000
# Pragma once
# Endif
# Ifndef _ cstdio _
# DEFINE _ cstdio _
# Ifdef _ std_using
# UNDEF _ std_using
# Include <stdio. h>
# DEFINE _ std_using
# Else
# Include <stdio. h>
# Endif/* _ std_using */
# Endif/* _ cstdio _*/
/*
* Copyright (c) 1994 by P. J. plauger. All rights reserved.
* Consult your license regarding permissions and restrictions.
*/
As you can see above, <cstdio> contains <stdio. h>.
See example 1:
# Include <stdio. h>
# Include <math. h>
Void main ()
{
Float I = 89.0000;
Float d = sin (I );
Printf ("% F \ n", I, D );
}
The program in Example 1 is correct.
Example 2:
# Include <cstdio>
# Include <math. h>
Void main ()
{
Float I = 89.0000;
Float d = sin (I );
Printf ("% F \ n", I, D );
}
The program in example 2 is also correct. We can use both C ++ standard library files and C-style header files in the program.
Example 3:
# Include <iostream>
# Include <math. h>
Void main ()
{
Float I = 89.0000;
Float d = sin (I );
Printf ("% F \ n", I, D );
}
The program in Example 3 is also correct. <Iostream> compatible with <stdio. h> in C.
Example 4:
# Include <stdio. h>
# Include <cmath>
Using namespace STD;
Void main ()
{
Float I = 89.0000;
Float d = sin (I );
Printf ("% F \ n", I, D );
}
In Example 4, when running the program, the error "'std ': does not exist or is not a namespace .", Therefore, when a C-Language header file is contained, the namespace STD cannot be used afterwards.
Example 5:
# Include <iostream>
# Include <cmath>
Using namespace STD;
Void main ()
{
Float I = 89.0000;
Float d = sin (I );
Printf ("% F \ n", I, D );
}
The program in Example 4 is correct. When using the C ++ library, add "using namespace STD; "This statement introduces the name of the specified namespace to the current namespace.
When we write a C ++ header file and use it, we should put it under the root directory of the project folder we created, then in the C ++ source file # include "self-written header file name. H ".
If the suffix. H is not written, an error occurs during program compilation.