I really need help with this guys. This compiles and runs but does not give me the right output.

tfile.data:

Seth 19 1.7
Austin 20 1.8
Michael 21 1.9

#include <iostream>
#include <fstream>

using namespace std;

int main()
{
        ifstream fin;
        fin.open ("tfile.data");
        if (fin.fail())
        {
                cout <<"ERROR";
                exit(1);
        }
struct EMP
{
 string name;
 int age;
 double height;
} emp;
struct LISTNODE
        {
                EMP emp;
                LISTNODE *nxt;
                LISTNODE (EMP emp1, LISTNODE *nxt1=NULL)
                {
                        emp = emp1;
                        nxt = nxt1;
                };

        };
        LISTNODE *head = NULL;
        string number;
        while (fin >> number)
        {
                head = new LISTNODE(emp , head);
        }
        LISTNODE *ptr = head;
        while ( ptr != NULL)
        {
                cout << ptr->emp.name<<endl;
                cout << ptr->emp.age<<endl;
                cout << ptr->emp.height<<endl;
                ptr = ptr->nxt;
        }
return 0;
}

where are you setting the emp in the node. i see this block for file input

while (fin >> number)
        {
                head = new LISTNODE(emp , head);
        }

but with this you are not doing anything. first you need pull the information into your employee struct and then add it to you list.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.