Difference between using #include and #include in C++

前端 未结 5 1010
深忆病人
深忆病人 2020-11-29 23:16

What is the difference between using #include and #include> in C++? Which of the two is used and why is it is used?

5条回答
  •  情歌与酒
    2020-11-29 23:34

    The #include was common in C++ code prior to the C++ standard. The standard changed it to #include with everything from the header placed in the std namespace. (Thanks to litb for pointing out that the standard has never allowed .h headers.)

    There is no magic going on, the first looks for a file called 'foo.h' and the second for a file called 'foo'. They are two different files in the file system. The standard just changed the name of the file that should be included.

    In most compilers the old headers are still there for backwards compatibility (and compatibility with C), but modern C++ programs that want to follow the standard should not use them.

    In the case of standard C headers, the C++ versions have a c at the beginning, so the C header

    #include 
    

    becomes

    #include 
    

提交回复
热议问题