In this code of operator Overloading, i don't want to write "using namespace std" instead i want to include "std::" wherever required.
After adding "std::" after cout and cin, i am still getting Errors where else to include "std::".
#include<iostream>
//using namespace std;
class Complex
{
private:
int real, imag;
public:
Complex(int r = 0, int i = 0) : real(r), imag(i) {}
friend ostream & operator << (ostream &, const Complex &);
friend istream & operator >> (istream &, Complex &);
};
ostream & operator << (ostream &out, Complex &obj)
{
out<<obj.real<<" "<<obj.imag;
return out;
}
istream & operator >> (istream &in, const Complex &obj)
{
in>>obj.real>>obj.imag;
return in;
}
int main()
{
Complex obj;
std::cin>>obj;
std::cout<<obj;
return 0;
}
It should take input two numbers using istream operator and output two numbers using ostream operator.
ostream
andistream
from? – 463035818_is_not_a_number