2007年1月下载的孙鑫老师的《VC++视频教学》开始学习VC++
代码如下:
#include "iostream.h"
class Point
{
public:
int x;
int y;
/* void init()
{
x=0;
y=0;
}*/
Point()
{
x=0;
y=0;
}
Point(int a,int b)
{
x=a;
y=b;
}
~Point()
{
}
void output()
{
cout<<x<<endl<<y<<endl;
}
void output(int x,int y)
{
this->x=x;
this->y=y;
}
};
void main()
{
Point pt(3,3);
pt.output(5,5);
// pt.init();
//pt.x=5;
//pt.y=5;
// cout<<pt.x<<endl<<pt.y<<endl;
pt.output();
}
编译提示如下问题:
e:\vc\vc++深入详解教学视频\lesson2\code\point\point.cpp(1) : fatal error C1083: Cannot open include file: 'iostream.h': No such file or directory
解决办法:
将#include "iostream.h"修改为
#include "iostream"
using namespace std;
理由:
在标准C++以前,都是用#include<iostream.h>这样的写法的,因为要包含进来的头文件名是iostream.h。标准C++引入了名字空间的概念,并把iostream等标准库中的东东封装到了std名字空间中,同时为了不与原来的头文件混淆,规定标准C++使用一套新的头文件,这套头文件的文件名后不加.h扩展名,如iostream、string等等,并且把原来C标准库的头文件也重新命名,如原来的string.h就改成cstring(就是把.h去掉,前面加上字母c),所以头文件包含的写法也就变成了#include <iostream>。
并不是写了#include<iostream>就必须用using namespace std;我们通常这样的写的原因是为了一下子把std名字空间的东东全部暴露到全局域中(就像是直接包含了iostream.h这种没有名字空间的头文件一样),使标准C++库用起来与传统的iostream.h一样方便。如果不用using namespace std;使用标准库时就得时时带上名字空间的全名,如std::cout << "hello" << std::endl; #include "iostream"与#include<iostream>的区别:前者先在当前目录找iostream文件,找不到再去系统头文件路径找,后者反之。
(注:以上问题解决方法来源于网络)