错误: fatal error C1083: Cannot open include file: 'iostream.h': No such file or directory
我的源代码测试回调函数,编译不通过,出现如上错误。
原因:
将#include <iostream.h>改为
#include <iostream>using namespace std;
新的c++标准库摒弃了.h的头文件形式,因此是没有iostream.h文件的。在老的编辑环境中,例如VC6里面,iostream.h的形式还是存在的,因此你的程序在VC6里面是可以编译通过的。但是vs2005及以上的版本,对应新的c++标准,引入了名字空间的概念,没有.h的形式。
我的错误源码:
#include "stdafx.h"
#include "windows.h"
#include <iostream.h>
//回调函数指针
typedef int(WINAPI* WNDCALLBACK)(int*,int*);
//回调函数
int __stdcall Call(int *a,int *b);
//定义类
class A
{
public:
//比较两个数字大小
int Compare(int m,int n,WNDCALLBACK function)
{
int *a=&m;
int *b=&n;
return (*function)(a,b);
}
};
int main(int argc, char* argv[])
{
int a=10;
int b=6;
A m_a;
cout<<m_a.Compare(a,b,Call)<<endl;
return 0;
}
//回调函数
int CALLBACK Call(int *a,int *b)
{
return *a>(*b)?(*a):(*b);
}