- Answer to C #include 'stdafx.h' #include #include using namespace std; // base class animal class animal // declare the requir. Skip Navigation Chegg home.
- Sep 09, 2011 Put #include and #include in stdafx.h. Also, you can use Alt+F7 in VS Configuration Properties C/C Precompiled Headers to see difference in these projects. David already gave you a link to info about Precompiled Headers.
- Configuration Properties - C/C - Advanced Type 'stdafx.h' in the 'Force Include File' field; this will make the visual studio compiler insert the header file at the beginning of each file without having to include it manually. Configure Visual Studio to use precompiled headers.
Oct 24, 2019 Precompiled Header Files.; 13 minutes to read; In this article. When you create a new project in Visual Studio, a precompiled header file named pch.h is added to the project. (In Visual Studio 2017 and earlier, the file was called stdafx.h.)The. Go to 'C/C'-'Precompiled Headers' and change 'Precompiled Header File' value to the path relative to the solution directory, e.g. PROJECTNAME/stdafx.h In your.cpp files include 'PROJECTNAME/stdafx.h', instead of just 'stdafx.h'.
-->Tells the preprocessor to treat the contents of a specified file as if they appear in the source program at the point where the directive appears.
Syntax
#include 'path-spec'
#include <path-spec>
#include <path-spec>
Remarks
You can organize constant and macro definitions into include files and then use #include directives to add them to any source file. Include files are also useful for incorporating declarations of external variables and complex data types. The types may be defined and named only once in an include file created for that purpose.
The path-spec is a file name that may optionally be preceded by a directory specification. The file name must name an existing file. The syntax of the path-spec depends on the operating system on which the program is compiled.
For information about how to reference assemblies in a C++ application that's compiled by using /clr, see #using.
Both syntax forms cause that directive to be replaced by the entire contents of the specified include file. The difference between the two forms is the order in which the preprocessor searches for header files when the path is incompletely specified. The following table shows the difference between the two syntax forms.
Syntax Form | Action |
---|---|
Quoted form | The preprocessor searches for include files in this order: 1) In the same directory as the file that contains the #include statement. 2) In the directories of the currently opened include files, in the reverse order in which they were opened. The search begins in the directory of the parent include file and continues upward through the directories of any grandparent include files. 3) Along the path that's specified by each /I compiler option. 4) Along the paths that are specified by the INCLUDE environment variable. |
Angle-bracket form | The preprocessor searches for include files in this order: 1) Along the path that's specified by each /I compiler option. 2) When compiling occurs on the command line, along the paths that are specified by the INCLUDE environment variable. |
The preprocessor stops searching as soon as it finds a file that has the given name. If you enclose a complete, unambiguous path specification for the include file between double quotation marks (
' '
), the preprocessor searches only that path specification and ignores the standard directories.If the file name that's enclosed in double quotation marks is an incomplete path specification, the preprocessor first searches the 'parent' file's directory. A parent file is the file that contains the #include directive. For example, if you include a file named file2 in a file named file1, file1 is the parent file.
Include files can be 'nested': An #include directive can appear in a file that's named by another #include directive. For example, file2 could include file3. In this case, file1 would still be the parent of file2, but it would be the 'grandparent' of file3.
Stdafx.h Dev C++
When include files are nested and when compiling occurs on the command line, directory searching begins in the directories of the parent file. Then it proceeds through the directories of any grandparent files. That is, searching begins relative to the directory that contains the source that's currently being processed. If the file isn't found, the search moves to directories that are specified by the /I (Additional include directories) compiler option. Finally, the directories that are specified by the INCLUDE environment variable are searched.
From the Visual Studio development environment, the INCLUDE environment variable is ignored. For information about how to set the directories that are searched for include files and library files, see VC++ Directories Property Page.
#include Stdafx.h C++
This example shows file inclusion by using angle brackets:
This example adds the contents of the file named STDIO.H to the source program. The angle brackets cause the preprocessor to search the directories that are specified by the INCLUDE environment variable for STDIO.H, after it searches directories that are specified by the /I compiler option.
The next example shows file inclusion by using the quoted form:
This example adds the contents of the file that's specified by DEFS.H to the source program. The quotation marks mean that the preprocessor first searches the directory that contains the parent source file.
Stdafx Not Found
Nesting of include files can continue up to 10 levels. When the nested #include is processed, the preprocessor continues to insert the enclosing include file into the original source file.
Microsoft Specific
To locate includable source files, the preprocessor first searches the directories that are specified by the /I compiler option. If the /I option isn't present, or if it fails, the preprocessor uses the INCLUDE environment variable to find any include files within angle brackets. The INCLUDE environment variable and /I compiler option can contain multiple paths, separated by semicolons (;). If more than one directory appears as part of the /I option or within the INCLUDE environment variable, the preprocessor searches them in the order in which they appear.
For example, the command
causes the preprocessor to search the directory D:MSVCINCLUDE for include files such as STDIO.H. The commands
have the same effect. If both sets of searches fail, a fatal compiler error is generated.
If the file name is fully specified for an include file that has a path that includes a colon (for example, F:MSVCSPECIALINCLTEST.H), the preprocessor follows the path.
For include files that are specified as
#include 'path-spec'
, directory searching begins with the directory of the parent file and then proceeds through the directories of any grandparent files. That is, searching begins relative to the directory that contains the source file that contains the #include directive that's being processed. If there is no grandparent file and the file has not been found, the search continues as if the file name were enclosed in angle brackets.![Include Stdafx.h Dev C++ Include Stdafx.h Dev C++](/uploads/1/2/6/1/126162077/370244592.jpg)
END Microsoft Specific
See also
Preprocessor directives
/I (Additional include directories)
/I (Additional include directories)
I've done Hello World programs with Visual C++ Express 2010 before, but I always checked the 'Empty Project' option. This time I selected a Console project and took the defaults. Program is below.
Errors are..
- Error : Name must be a namespace name (refers to 'std' on line 4)
- error C2065: 'cout' : undeclared identifier
#2 is pretty obvious given number 1. I'm pretty new to Visual Studio 2010 except for Empty console projects. Figure I'd check it out. The whole 'tmain' and 'stdafx.h' aspect is new to me, but I figured I'd try it out. Do I need to configure something to make it find namespace std?
- 3 Contributors
- forum 10 Replies
- 998 Views
- 17 Hours Discussion Span
- commentLatest Postby VernonDozierLatest Post
Recommended Answers
[QUOTE]Changing the order a bit seems to do the trick. Works now.[/QUOTE]
It works for the same reason that prototypes work the way they do. If you have a using directive, it applies to everything below the directive, but not above it. Here's an example that takes advantage of this …
Jump to PostIt works for the same reason that prototypes work the way they do. If you have a using directive, it applies to everything below the directive, but not above it. Here's an example that takes advantage of this …
All 10 Replies
Akill1096
Isn't the std namespace part of iostream? #include <iostream> should do it.
Also, I found this:
_tmain is a macro that expand to main o wmain according to _UNICODE macro. In
VC2005, By default , a program is unicode enabled (UNICODE and _UNICODE defined)
so your _tmain macro expands to wmain (not main) and _TCHAR expands to wchar_t.
_tmain is a macro that expand to main o wmain according to _UNICODE macro. In
VC2005, By default , a program is unicode enabled (UNICODE and _UNICODE defined)
so your _tmain macro expands to wmain (not main) and _TCHAR expands to wchar_t.
stdafx is a precompiled header, it should be under the header files of your project explorer and you can see what it includes.
Edited by Akill10: n/a