errors when compiling

Pages: 12
Feb 14, 2015 at 6:49am
When compiling I get a bunch of different errors such as "string does not name type" in EmployeeInfo.h also declaration does not declare anything in EmployeeInfo.h, also in payroll.cpp, Struct employee has no member named firstname and lastname, and other errors, I don't see where my errors are, please someone help me lol.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
  (Employeeinfo.h)
struct Date
{ 
    int month;
    int day;
    int year;
};

struct EmployeeInfo
{
int id;
string firstname;
string lastname;
Date birthday;
Date datehired;
double payrate;
int hours;
};

(payroll.cpp)
#include <iostream>
#include <iomanip>
#include <string>

#include "Employeeinfo.h"
using namespace std;
int main()
{
EmployeeInfo employee;
double grosspay, tax, netpay, totalgp=0, totaltax=0, count=0;
   cin  >>  employee.id  >> employee.firstname  >>  employee.lastname >> employee.birthday.month>>employee.birthday.day>>employee.birthday.year>>employee.datehired>>employee.payrate>>employee.hours;
while (count<10)
{
grosspay = employee.payrate * employee.hours;
if(grosspay>=1000)
tax = .25*grosspay;

else
{
	tax = .18*grosspay;
}
	netpay = grosspay - tax;
count++;
totalgp+= grosspay;
totaltax+= tax;
cout<<employee.id << employee.firstname << employee.lastname << employee.birthday.month <<employee.birthday.day<<employee.birthday.year<< employee.datehired << employee.payrate << employee.hours << tax << netpay << totalgp << totaltax<<endl;
return 0; 
}

Feb 14, 2015 at 6:52am
Did you #include <string> ?
Feb 14, 2015 at 6:54am
Yes, when compiling payroll.cpp, it has #include<string>
Feb 14, 2015 at 6:55am
You can't just include headers whenever and wherever you feel like it, you need to include them before they're used. #include <string> in your EmployeeInfo.h file.
Feb 14, 2015 at 6:58am
@LB I just included #include<string> to my EmployeeInfo.h file and still getting that "string does not name type" error in my EmployeeInfo.h file
Last edited on Feb 14, 2015 at 6:59am
Feb 14, 2015 at 7:14am
Anyone else see any mistakes ?
Feb 14, 2015 at 7:27am
Did you move using namespace std to the top? All of your libraries you are using need to be declared at the top of the file.
Feb 14, 2015 at 7:44am
@Mr D moving it before #include<Employee.h> didn't help, it actually gave me a bigger error than I had before.
Feb 14, 2015 at 7:47am
All your includes should be at the top, followed by your using namespace std.
Feb 14, 2015 at 7:50am
@Mr D I changed my source file to
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
#include "Employeeinfo.h"
(changed position of using namespace std)
I eliminated the string errors, but not I got a really really really long syntax error when im compiling it on unix. So is it just my code in general that is the problem ?
Feb 14, 2015 at 7:56am
1
2
3
4
5
#include <iostream>
#include <iomanip>
#include <string>
using namespace std; 
#include "Employeeinfo.h" // All your includes, followed by using namespace std, this is an include, isn't it? Switch this. 


Without knowing what the error code is, I can't help you. But, putting ALL of the includes FIRST, followed by the namespace should solve your issue.
Last edited on Feb 14, 2015 at 7:57am
Feb 14, 2015 at 7:58am
@Mr D well that was what I had to begin with, I just changed it to this after you told me to change using namespace std to the top.
Feb 14, 2015 at 7:59am
All your includes should be at the top, followed by your using namespace std.
1
2
3
4
5
#include <iostream>
#include <iomanip>
#include <string>
#include "Employeeinfo.h"
using namespace std;
Feb 14, 2015 at 8:01am
@Mr D again, that's what I had to begin with...
Feb 14, 2015 at 8:03am
Without knowing what the error code is, I can't help you.

Please, post your new code followed by the error code.
Last edited on Feb 14, 2015 at 8:04am
Feb 14, 2015 at 8:04am
if you dont want to declare using namespace std;
you should write std::string if you declare a string
this will fix it
Feb 14, 2015 at 8:06am
also, putting all includes first doesn't actually solve the issue because I would still get the string error, but after making the header file last, i would eliminate that error.
Feb 14, 2015 at 8:07am
Lorence30 is correct, but it won't fix your error. Declaring using namespace std brings in the entire namespace and is considered bad practice, whereas just typing using std::string at the top of the file ( under your includes and header files ) specifies that you ONLY want to use the string of the standard library, which in effect is the same as typing std::string every time you want to use it, except it saves you some typing.
Last edited on Feb 14, 2015 at 8:08am
Feb 14, 2015 at 8:08am
Just so everyone knows this is being compiled on Unix, NOT C++.
Feb 14, 2015 at 8:10am
Without posting your new code, and your error message, we CAN NOT help you.
Pages: 12