Pre-compiled header file: Error about "stdafx. H" cannot be opened or ended unexpectedly

Source: Internet
Author: User

Pre-compiled header file: Error about "stdafx. H" cannot be opened or ended unexpectedly

When I copied the H and CPP files from my colleagues, I encountered an error about "stdafx. H" which cannot be opened or ended unexpectedly"

The solution is:

You can select the C/C ++ option in the setting project, select precompiled headers from the category menu, and select not using precompiled headers.

Because when I copy it, the value of the CPP precompiled headers is to use the pre-compiled header file. because I am a beginner, I am not clear about the pre-compiled header file at the beginning. H and test. for example, I used # include "stdafx. H "written in test. test. CPP is not written, so this method can be used.

 

But I think again, if this method is used to solve the problem, then this test. CPP does not use pre-compiled header files, so it must be in test. h. if this stdafx is compiled in the CPP file. h, as a common header file, will definitely compile stdafx. h. This completely violates the original intention of using precompiled header files to speed up compilation.

 

But why do I write test. H and test. CPP will report this error (about "stdafx. h), because the CPP precompiled headers, the value is to use the pre-compiled header file (that is, stdafx. h as the pre-compiled header file), but my test. # include "stdafx. H ", so the pre-compiled header file will not be found when compiling the CPP, but I think my test. # include "stdafx. H "Ah, theoretically, after H is expanded to CPP, CPP is equivalent to # include" stdafx. H ", why are there still errors? When compiling any CPP file, it will first be determined based on your compilation header file options. If you choose to use the pre-compiled header file, the # include "stdafx. H "this line, find this line to directly jump to the next line to continue compilation (that is why # include" stdafx. H "Put it in the first line of the CPP file. If you put the second line, the first line will be skipped directly.) Continue the compilation process and find # include test. h, and then expand. Continue to compile .. If you cannot find # include "stdafx. H ", an error is returned. If you choose not to use the pre-compiled header file, the compilation will follow the normal compiling order. From top to bottom, # include test is encountered. h. Expand. # include "stdafx. H ", set stdafx. h. All the files contained in this section are compiled. Then proceed ..

The following is an excerpt from the Internet

 

The following describes how to use the pre-compiled header file and enjoy the improvement of the Compilation speed brought by the Pre-compiled header file:

1) Add an stdafx. h file (name is whatever you want, and the default name provided by vs is used here. include the header file to be used in the H file (usually an external library, you can also add the infrequently changed header files you write)

2) Add a stdafx. cpp file and include "stdafx. H"

3) set project properties to use precompiled header and stdafx. h.

4) stdafx. cpp properties --> C/C ++-> precompiled is set to create precompiled header, stdafx. h

 

 

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.