alright say i have a data file i want to open up and extract the data into a binary tree...

i do this to open the file:

binaryTree::information() {
                      
    ifstream file;
    file.open ("proj4.dat");
       
}

although ill have more in that after i learn how to do it..

and i have this class with the struct in it:

#include <iostream>
#include <cstdlib>
#include <fstream>
using namespace std;



class binaryTree {

	public:

		binaryTree ();
		~binaryTree ();
		void menu ();

	private:

		struct info {
       
               string employee;
               string lastName;
               string firstName;
               char middleInitial;
               string state;
               string zipcode;
               string department;
               int yearsWorked;
               int salary;
               struct info * right;
               struct info * left;  
        };
	
		info * root;
		void information (info &);
        void insert (info *, info &);
		void retrieveAll (info *);
		void retrieveOpen (info *);
		void retrieveCity (info *);

};

now the data file has the employee id, the first name, last name etc.

how do i get the info from the file into my program?

do i have to do like...

file.getline(something) = info.employee

what is the correct method for this?

Recommended Answers

All 2 Replies

so i got that worked out but now...

more one quick question about this...

say i use:

void binaryTree::information(info & person) { 
                      
    ifstream file; 
    file.open ("proj4.dat"); 
    
    file >> person.employee; 
    file >> person.lastName; 
    file >> person.firstName; 
    file >> person.middleInitial; 
    file >> person.state; 
    file >> person.zipcode; 
    file >> person.department; 
    file >> person.yearsWorked; 
    file >> person.salary; 
        
}

will this work now and have those values stored?

void binaryTree::insert(info * tree, info & person) { 

    if (tree == NULL) { 
  
        tree = new dataNode; 
        tree -> left = NULL; 
      tree -> right = NULL; 
      strcpy(tree -> employee, person.employee); 
      strcpy(tree -> lastName, person.lastName); 
        strcpy(tree -> firstName, person.firstName); 
        tree -> middleInitial = person.middleInitial; 
        strcpy(tree -> state, person.state); 
        strcpy(tree -> zipcode, person.zipcode); 
        strcpy(tree -> department, person.department); 
        tree -> yearsWorked = person.yearsWorked; 
        tree -> salary = person.salary; 
        
   } 
}

and will it create my tree...

if i do this?

info person; 
     information(person); 
     insert(root, person);

What about just trying, and THEN post your questions when it does not work.
I'm sure that your compiler is faster than your web browser when dealing with c++ code.

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.