我是C++的新手,正在爲一個類進行任務。我們獲得了一個.txt文件,必須從中讀取信息,並將其存儲在鏈接列表中,然後將其打印出來給用戶。經過幾個小時的試圖操縱我們得到的例子,還有幾個小時試圖從頭開始編寫代碼,我接近兩個小時。C++鏈接器錯誤
該文件稱爲payroll.txt並且在這種類型的格式的大約30行左右:
克拉克肯特55000 2500 0.07
路易絲萊恩65000 1000 0.06
託尼斯塔克70000 1500 0.05
我們教授在評論我們的代碼時真的很重要,所以我希望它有幫助。這是我的代碼:
#include <cstdlib>
#include <stdio.h>
#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;
#define MAX_STR 100
/* Structure Definition */
typedef struct employeeType Employ;
struct employeeType {
char first[MAX_STR]; /* first name */
char last[MAX_STR]; /* last name */
int salary; /* salary */
int bonus; /* bonus */
double deduc; /* percent deduction */
Employ *next;
};
/* operations on the data */
Employ *ReadRecord();
void PrintRecord(Employ *);
main()
{{
Employ *head, *tail, *newp, *tmp;
head = tail = newp = tmp = NULL;
FILE *in; /* file description */
/* open a file, check if it's there */
if((in = fopen("payroll.txt", "r")) == NULL)
{
printf("Error opening file\n");
exit(1);
}
while(newp = ReadRecord())
{
/* Add object to the list */
if(head == NULL)
{
/* Beginning of the list */
head = newp;
/* Current record */
tail = newp;
}
else
{
/* Previous record reference to new record */
tail->next = newp;
/* Current record */
tail = newp;
}
}
/* End of the list */
tail->next = NULL;
/* Loop through the list */
for(tmp=head; tmp!=NULL; tmp=tmp->next)
{
PrintRecord(tmp);
}
現在,當我編譯,我得到的錯誤:
[鏈接錯誤]未定義參考ReadRecord()
[鏈接錯誤]未定義參考PrintRecord(employeeType *)
我幾乎可以肯定他在這個例子中給我們的ReadRecord和PrintRecord命令是僞代碼,這意味着我們搞砸了,但是我不知道該怎麼去那裏。我一直在翻閱多本教科書,並尋找一種簡單的方法來修復在線鏈接錯誤,並且已經用完了想法。
如果有人能幫助我/指出我在正確的方向,將不勝感激。鏈接到鏈接列表和鏈接器錯誤更多信息的網頁鏈接將更加棒。
謝謝
亞當
是否使用的是C++編譯器? – 2010-07-06 14:59:37
我正在使用Dev-C++。 – AdamY 2010-07-06 15:03:00
您應該添加C標籤。除了包含的頭文件和'using'子句,這幾乎不是C++。 – pmr 2010-07-06 15:10:31