2

I'm trying to write a very basic c++ code using visual studio. the code doesn't compile because of the 'cin' and 'cout'. here is the code:

#include <iostream>

using namespace std;

class employer
{
private:
    string id;
    float work_hours, over_time_hours,hourly_salary,salary;
public:
    employer()
    {
        id="123456789";
        hourly_salary=25;
        work_hours=0;
        over_time_hours=0;
        salary=0;
    }
    void get_employer()
    {
        cin >> id >> salary >> work_hours >> over_time_hours;
    }
    void print_employer()
    {
        cout << "I.D. #" << id << "\n and his hourly salary is: " << salary << '\n';
    }
        void salary_calculation()
    {
        salary= (work_hours*hourly_salary + 1.5*over_time_hours*hourly_salary);
    }

};
int main(){
    employer employer1;
    employer1.get_employer();
    employer1.salary_calculation();
    employer1.print_employer();
    return 0;
}

and the compilation error is:

"1>ex1.cpp(21): error C2678: binary '>>' : no operator found which takes a left-hand operand of type 'std::istream' (or there is no acceptable conversion)"
Andreas Fester
  • 36,091
  • 7
  • 95
  • 123
user107761
  • 39
  • 2
  • 8

1 Answers1

8

operator>> overloads for string are located in string header, so you should include it:

#include <string>
yuyoyuppe
  • 1,582
  • 2
  • 20
  • 33