3
我開始自學C++,遇到了一個錯誤,我認爲這個錯誤非常簡單,但沒有捕捉到它。我創建了主命名EmployeeT.h結構錯誤
#ifndef EMPLOYEET_H_INCLUDED
#define EMPLOYEET_H_INCLUDED
typedef struct
{
char firstInitial;
char middleInitial;
char lastInitial;
int employeeNumber;
int salary;
} EmployeeT
#endif // EMPLOYEET_H_INCLUDED
下面的頭文件作爲
#include <iostream>
#inclide <Employee.h>
using namespace std;
int main()
{
EmployeeT anEmployee;
anEmployee.firstInitial = 'M';
anEmployee.middleInitial = 'R';
anEmployee.lastInitial = 'G';
anEmployee.employeeNumber = 42;
anEmployee.salary = 80000;
cout << "Employee: " << anEmployee.firstInitial <<
anEmployee.middleInitial <<
anEmployee.lastInitial << endl;
cout << "Number: " << anEmployee.employeeNumber << endl;
cout << "Salary: " << anEmployee.salary <<endl;
return 0;
}
你還沒有提到錯誤。而且,絕對不需要在C++中使用'typedef struct {} blah;'。只需使用'struct blah {};'。 C++提供比普通C結構更多的功能,例如可用於此的構造函數,以及運算符重載,這對於打印它很有用,但後者對於您現在需要的內容可能稍微先進一些。 – chris
除了缺少分號*包含*'EmployeeT.h'和'Employee.h'將是不同的文件。 – Joe
您是否收到任何錯誤?新聞告訴我們他們是什麼。 – 0x499602D2