purusingh
Jan 5th, 2003, 08:35 AM
#include <iostream.h>
class complex
{
float real,imag;
public:
complex();
complex(float a,float b);
friend ostream& operator<< ( ostream& os, complex& dt );
friend istream& operator>> ( istream& is, complex& dt );
};
#include "complex.h"
complex::complex()
{
real=imag=0.0;
}
complex::complex(float a,float b)
{
real=a;
imag=b;
}
ostream& operator<< ( ostream& s, complex& dt )
{
s << dt.real << dt.imag;
return s;
}
istream& operator>> ( istream& s, complex& dt )
{
s >> dt.real >> dt.imag;
return s;
}
#include "complex.h"
#include <fstream.h>
#include <conio.h>
void main()
{
char c;
cout <<"Press s for save "<<endl;
cin >>c;
if (c=='S' || c=='s')
{
complex a=complex(1.2,3.4);
ofstream os("c:\\abc.txt");
os<<a;
cout << a;
}
else
{
complex a;
ifstream is("c:\\abc.txt");
is >> a;
cout << a;
}
while (!kbhit());
}
why this program different result in bc++ and vc++?
class complex
{
float real,imag;
public:
complex();
complex(float a,float b);
friend ostream& operator<< ( ostream& os, complex& dt );
friend istream& operator>> ( istream& is, complex& dt );
};
#include "complex.h"
complex::complex()
{
real=imag=0.0;
}
complex::complex(float a,float b)
{
real=a;
imag=b;
}
ostream& operator<< ( ostream& s, complex& dt )
{
s << dt.real << dt.imag;
return s;
}
istream& operator>> ( istream& s, complex& dt )
{
s >> dt.real >> dt.imag;
return s;
}
#include "complex.h"
#include <fstream.h>
#include <conio.h>
void main()
{
char c;
cout <<"Press s for save "<<endl;
cin >>c;
if (c=='S' || c=='s')
{
complex a=complex(1.2,3.4);
ofstream os("c:\\abc.txt");
os<<a;
cout << a;
}
else
{
complex a;
ifstream is("c:\\abc.txt");
is >> a;
cout << a;
}
while (!kbhit());
}
why this program different result in bc++ and vc++?