How do I overload the cout and cin operators so as to get input and show output using an object?
Heres a simple example of what I'm trying to do:
class Temp{
double fTemp;
public:
double FahrToCelsius(double fTemp){
return (fTemp - 32.0) / 1.8;
}
friend std::ostream operator<<(std::ostream Out, const Temp& tempVar); //overloading of the ostream "cout"
friend std::istream& operator>>(std::istream& In, Temp& tempVar); //overloading of the istream "cin"
}
//using namespace std
int main(void){
Temp tempVar; //create object
cout << "Enter fahrenheit temp: " << endl;
cin >> tempVar;
cout << "Fahrenheit Temp: " << tempVar.FahrToCelsius(tempVar);
return 0;
}
Am I doing it wrong or is there a way to overload the operators?