#include <string>
using namespace std;
struct Date
{
int month;
int day;
int year;
};
struct EmployeeInfo
{
int id;
string firstname;
string lastname;
Date birthday;
Date datehired;
double payrate;
int hours;
};
----------------------------------------
Employeeinfo.h:12: error: `string' does not name a type
Employeeinfo.h:13: error: `string' does not name a type
lab2sourcefile.cpp: In function `int main()':
lab2sourcefile.cpp:10: error: 'struct EmployeeInfo' has no member named 'firstname'
lab2sourcefile.cpp:10: error: 'struct EmployeeInfo' has no member named 'lastname'
lab2sourcefile.cpp:26: error: 'struct EmployeeInfo' has no member named 'firstname'
lab2sourcefile.cpp:26: error: 'struct EmployeeInfo' has no member named 'lastname'
Employeeinfo.h:12: error: `string' does not name a type
Employeeinfo.h:13: error: `string' does not name a type
string is defined inside the iostream library, and the functions of strings is define in string library. so including string header wont fix this error.
lab2sourcefile.cpp:10: error: 'struct EmployeeInfo' has no member named 'firstname'
lab2sourcefile.cpp:10: error: 'struct EmployeeInfo' has no member named 'lastname'
lab2sourcefile.cpp:26: error: 'struct EmployeeInfo' has no member named 'firstname'
lab2sourcefile.cpp:26: error: 'struct EmployeeInfo' has no member named 'lastname'
this will not show anymore if you fix the string errors
No. String defined inside <string> header. It is iostream which happens to include part of the string header in particular implementation. Including iostream will not give you access to string.
i get like a REALLLLLLLLLLLY long error after I did that.
i mean , only in employee header file, just #include <iostream>
i didnt say to modify the headers included in cpp too
#include<iostream>
#include <string>
using namespace std;
struct Date
{
int month;
int day;
int year;
};
----------------
struct EmployeeInfo
{
int id;
string firstname;
string lastname;
Date birthday;
Date datehired;
double payrate;
int hours;
};
i can declare string type just including iostream.
And I can drive my car speeding past three red lights in a row and not crash or have any problems with the police. Does that mean that this is how it will be everytime and for everyone?
Standard library headers can include other headers. But not every header will include other header everytime.
For example string will not be brought in by including iostream at my workplace (it does brings basic_string, but not type alias std::string).
You should always include headers containing entity you want to use and never rely that something will include it (unless it is documented that it should always happens)
The compiler does not know how to cin datehired. You have to two choices:
1) cin the individual fields like you did with birthday.
2) Overload the the >> operator for Date.
1 2 3
friend istream & operator >> (istream & is, Date & date)
{ is >> date.month >> date.day >> date.year;
}
Ditto for cout. cout the individual fields or overload the the << operator.
PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post. http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.