我是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