So i'm currently making a code that is supposed to carry employee data based on the users input. The user inputs data and then a new object is created that will carry it later. But i have some questions.
1. When outputting the vector (employees) i get this error.
error: no match for 'operator<<' (operand types are 'std::ostream {aka std::basic_ostream}' and '__gnu_cxx::__alloc_traits >::value_type {aka Employee}')
Any idea why?
2. Have i done correct in creating a new object everytime the user presses 1 and then inputs the info. My idea is to after i've created the object in the vector apply it.
you either need to overload a << operator for cout to use for the employee class or rewrite your code to feed cout something it can handle, such as
cout << employees[0].name;
The code looks ok as far as it goes. I would think since employees is a vector you would loop over input until the user enters a zero to quit.
Its <cstdio> not stdio.h, to use the c++ version of the header (minor but can cause issues in large projects).
Its a little weird to just quit without any warns if neither 0 nor 1 are entered. But that looks like a 'not done yet' problem, more than a real problem.
error: no match for'operator<<' (operand types are 'std::basic_ostream' and '__gnu_cxx::__alloc_traits >::value_type {aka Employee}')
This is saying it doesn't know how to handle an operation with the << operator between your cout and your Employee, e.g. cout << Employee. (cout is an std::basic_ostream).
Look at your line 83, specifically the end of it. It looks like you're trying to print out the wage. You forgot to add the ".wage" to the end.
You re-create your vector every loop iteration because all of your logic is surrounding by your while loop. Is this intended?
Also, let's step through your logic here. employeeCount is initially 0. The size of your vector is also initially 0. (In fact, your use of the employeeCount variable is redundant because std::vectors keep track of their own size(), employees.size(). ) Then, you push_back an Employee, and increment Employee count by 1. But array/vector indices start at 0, not 1. You are trying to access employees[1], but the first element of employees is at index 0. Try changing employees[employeeCount] to employees[employeesCount-1], or equivalently, just do employees.back().