iostream与iostream.h的区别
#include<iostream>using namespace std;
class Complex
{
public:
Complex() { real=0;imag=0; }
Complex(double r,double i) { real=r; imag=i; }
Complex operator +(Complex &c2);
friend ostream& operator<<(ostream&,Complex&);
private:
double real;
double imag;
};
Complex Complex::operator+(Complex &c2)
{ return Complex(real+c2.real,imag+c2.imag); }
ostream& operator<<(ostream &output,Complex &c)
{
output<<"("<<c.real<<"+"<<c.imag<<"i)"<<endl;
return output;
}
int main()
{
Complex c1(2,4),c2(6,10),c3;
c3=c1+c2;
cout<<c3;
return 0;
}
上面这个程序在vc环境中试无法通过的,必须得将第一行修改成为
#include <iostream.h>
同时删去第二行才可以,这是为什么呢