errors when compiling

Pages: 12
this is being compiled on Unix, NOT C++.
I drive a road, not a car.

Unix is OS, C++ is programming language. You can compile C++ with GCC (compiler) under Unix, and it will not change the fact that you do use C++.
#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;
};
----------------------------------------

#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;
}

Errors

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'
Last edited on
but after making the header file last, i would eliminate that error. 

yes, because you havent use any members of those headers yet.

just #include <iostream> at the top of Employeeinfo.h
@Lorence30 i get like a REALLLLLLLLLLLY long error after I did that.
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


way#1
1
2
#include <iostream>
using namespace std;

way#2
1
2
#include <iostream>
std::string variablename;
Did you create a class file for those two structs? I'm not experienced, but i'm pretty sure that's not allowed.
string is defined inside the iostream library
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.
@MiiNiPaa
i can declare string type just including iostream.
You can also simply type using std::string; and it's the same as typing std::string before each declaration.
Last edited on
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
Last edited on
#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;
};

#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;
}

This gives me a REALLY long error when compiling on unix but i no longer get the string type error.
Unix has nothing to do with it. Post your error code.
lab2sourcefile.cpp: In function `int main()':
lab2sourcefile.cpp:10: error: no match for 'operator>>' in '(+(+(+std::operator>> [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>](((std::basic_istream<char, std::char_traits<char> >&)(+std::operator>> [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>](((std::basic_istream<char, std::char_traits<char> >&)(+(&std::cin)->std::basic_istream<_CharT, _Traits>::operator>> [with _CharT = char, _Traits = std::char_traits<char>](((int&)((int*)(&employee)))))), ((std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)(((std::string*)(&employee)) + 4u))))), ((std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)(((std::string*)(&employee)) + 8u))))->std::basic_istream<_CharT, _Traits>::operator>> [with _CharT = char, _Traits = std::char_traits<char>](((int&)((int*)(((Date*)(&employee)) + 12u)))))->std::basic_istream<_CharT, _Traits>::operator>> [with _CharT = char, _Traits = std::char_traits<char>](((int&)(((int*)((Date*)(&employee))) + 16u))))->std::basic_istream<_CharT, _Traits>::operator>> [with _CharT = char, _Traits = std::char_traits<char>](((int&)(((int*)((Date*)(&employee))) + 20u))) >> employee.EmployeeInfo::datehired'
/usr/sfw/lib/gcc/sparc-sun-solaris2.10/3.4.3/../../../../include/c++/3.4.3/bits/istream.tcc:87: note: candidates are: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(std::basic_istream<_CharT, _Traits>&(*)(std::basic_istream<_CharT, _Traits>&)) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/sfw/lib/gcc/sparc-sun-solaris2.10/3.4.3/../../../../include/c++/3.4.3/bits/istream.tcc:93: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(std::basic_ios<_CharT, _Traits>&(*)(std::basic_ios<_CharT, _Traits>&)) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/sfw/lib/gcc/sparc-sun-solaris2.10/3.4.3/../../../../include/c++/3.4.3/bits/istream.tcc:102: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(std::ios_base&(*)(std::ios_base&)) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/sfw/lib/gcc/sparc-sun-solaris2.10/3.4.3/../../../../include/c++/3.4.3/bits/istream.tcc:111: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(bool&) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/sfw/lib/gcc/sparc-sun-solaris2.10/3.4.3/../../../../include/c++/3.4.3/bits/istream.tcc:133: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(short int&) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/sfw/lib/gcc/sparc-sun-solaris2.10/3.4.3/../../../../include/c++/3.4.3/bits/istream.tcc:164: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(short unsigned int&) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/sfw/lib/gcc/sparc-sun-solaris2.10/3.4.3/../../../../include/c++/3.4.3/bits/istream.tcc:186: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(int&) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/sfw/lib/gcc/sparc-sun-solaris2.10/3.4.3/../../../../include/c++/3.4.3/bits/istream.tcc:217: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(unsigned int&) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/sfw/lib/gcc/sparc-sun-solaris2.10/3.4.3/../../../../include/c++/3.4.3/bits/istream.tcc:239: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(long int&) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/sfw/lib/gcc/sparc-sun-solaris2.10/3.4.3/../../../../include/c++/3.4.3/bits/istream.tcc:261: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(long unsigned int&) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/sfw/lib/gcc/sparc-sun-solaris2.10/3.4.3/../../../../include/c++/3.4.3/bits/istream.tcc:284: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(long long int&) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/sfw/lib/gcc/sparc-sun-solaris2.10/3.4.3/../../../../include/c++/3.4.3/bits/istream.tcc:306: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(long long unsigned int&) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/sfw/lib/gcc/sparc-sun-solaris2.10/3.4.3/../../../../include/c++/3.4.3/bits/istream.tcc:329: note: std::basic_istream<_CharT, _Traits>& std:
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)
Standard library headers can include other headers.


oh it does makes sense to me
@lorence30 no it doesn't.
@leashbomb69
i think you are getting your error about calling the members of object of DATE for some reasons i dont know
You have two errors in your program, both related to datehired.

1
2
3
cin >> employee.id >> employee.firstname >> employee.lastname 
    >> employee.birthday.month >> employee.birthday.day >> employee.birthday.year 
    >> employee.datehired >> employee.payrate >> employee.hours;

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;
}


1
2
3
4
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;

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.
Last edited on
Topic archived. No new replies allowed.
Pages: 12