Error C1083: Cannot open include file: 'stdafx.h'

前端 未结 6 1638
小鲜肉
小鲜肉 2020-12-03 14:40

When I compiled this program (from C++ Programming Language 4th edition):

main.cpp

#include 
#include 
#incl         


        
6条回答
  •  情书的邮戳
    2020-12-03 14:58

    You have to properly understand what is a "stdafx.h", aka precompiled header. Other questions or Wikipedia will answer that. In many cases a precompiled header can be avoided, especially if your project is small and with few dependencies. In your case, as you probably started from a template project, it was used to include Windows.h only for the _TCHAR macro.

    Then, precompiled header is usually a per-project file in Visual Studio world, so:

    1. Ensure you have the file "stdafx.h" in your project. If you don't (e.g. you removed it) just create a new temporary project and copy the default one from there;
    2. Change the #include to #include "stdafx.h". It is supposed to be a project local file, not to be resolved in include directories.

    Secondly: it's inadvisable to include the precompiled header in your own headers, to not clutter namespace of other source that can use your code as a library, so completely remove its inclusion in vector.h.

提交回复
热议问题