#pragma once: Ensure that header files are compiled only once. This way, is unique to the Microsoft compiler, but also later, so know not many people, with the people are not many, because he does not support cross-platform. If you want to write cross-platform code, it's best to use the previous one. This is a way that the compiler provides support to prevent two compilations of the same file, where the same file refers to a physical file.
#ifndef #define // Code #endif
This is a C + + language-related, which is a macro definition in the C + + language that avoids multiple compilations of files through macro definitions. So it works on all compilers that support the C + + language, and it's best to use this approach if you're writing programs that cross-platform
Comparison:
#ifndef的方式依赖于宏名字不能冲突, this will not only guarantee that the same file will not be included multiple times, but also ensure that two files with exactly the same content will not be included accidentally. Of course, the disadvantage is that if the macro name of the different header accidentally "crash", it may lead to the header file exists, the compiler insists that cannot find the state of the statement
#pragma once is guaranteed by the compiler: the same file will not be included more than once. Note that the "same file" here refers to a physical file, not two files of the same content. The advantage is that you don't have to bother thinking about a macro name, and of course there's no strange problem with the macro name collision. The disadvantage is that if a header file has multiple copies, this method does not guarantee that they will not be included repeatedly. Of course, duplicate inclusions are more susceptible to discovery and remediation than the "no claims" issue caused by macro name collisions.
#pragma once and #ifndef