好久没写C++程序了,碰到了很多问题。伤心中,加油,一点一点慢慢来,重拾的过程,理解能力还是不错的,呵呵,自我安慰 一下。
以前在VC6中写的简单的单文件的C++单文件程序中没注意到"stdafx.h"这个文件,先把它拿来看一看:
1、当我们建立一个空工程时,当然你里面是什么文件都没有的
2、当我们建立一个“hello world”工程是,出现了两个不速之客
这个程序可以运行,看我们的主函数:
// del1.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
int main(int argc, char* argv[])
{
printf("Hello World!\n");
return 0;
}
我们没有看到有“error C2065: 'printf' : undeclared identifier”的错误产生,看来stdio.h这个头文件已经编译到本工程中了,那么,他在哪儿呢?
//StdAfx.cpp文件
// stdafx.cpp : source file that includes just the standard includes
// del1.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information
#include "stdafx.h"
// TODO: reference any additional headers you need in STDAFX.H
// and not in this file
//---------------------------------------------------------------------------------------------
//StdAfx.h文件:
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//
#if !defined(AFX_STDAFX_H__8B8838C4_046A_4930_B82A_68E89A686214__INCLUDED_)
#define AFX_STDAFX_H__8B8838C4_046A_4930_B82A_68E89A686214__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#include <stdio.h> //<<<--------------------------------------------------------看这里
// TODO: reference additional headers your program requires here
//{
{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_STDAFX_H__8B8838C4_046A_4930_B82A_68E89A686214__INCLUDED_)
果然,他被包含在StdAfx.h了。
3、我们再建立一个空的MFC工程: