ok my getData() function reads a text file and stores it into an array called info, and everytime it reads a letter from that file it calls a member called addRear which comes from my link list class "slist". what i need help on is how could i display this information using my Printdata function and display in on the screen on a readable format like below, please any help. Also my link list class has a member called displayAll which displays all the elements on the link list

lets say the my text file looks something like this

A 2 B C
B 1 D
C 1 A
D 2 C A

#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include "slist.h"
#include "ll.C"
using namespace std;

void getData();
void printData();

const int SIZE = 10;

struct info
  char vertexName;
  int outDegree;
  slist adjacentOnes; // this comes from slist.h which is a link list class                                                   

int main()


//PURPOSE: GETS DATA FROM THE FILE                                                                                            
void getData()
 ifstream fin("table.txt"); // opens the file
  string line; // declares line as a string

  // goes on a for loop and reads every variable, if variable is
  // a letter it calls addRear and appends it to the back of a list
  for(int i = 0; i<SIZE && getline(fin, line); i++)
      istringstream S(line);
      S >> table[i].vertexName >> table[i].outDegree;
      char x;
      while(S >> x)


void printData()

5 Years
Discussion Span
Last Post by Lerner

Your objective isn't very clear.

Where does the array called table come from? I assume it's an array of type info, but I don't see any declaration.

I assume you want to print out the contents of table so that the information printed to the screen looks like the file, that is each line contains the information for one info object. To do that you need to keep track of how many info objects are actually stored in table. Then have each object print itself. To have each object print itself overload the << operator (or use an appropriately named method) to print vertexName to the screen followed by a space followed by the outDegree variable followed by a space and then call the displayAll() method to display each info objects slist. The last action just described may look something like table.adjacentOnes.displayAll();


you are correct i forgot to include it here
info table;

and how could i keep track of how many objects are stored in the table?


Does your getData() function work? If it doesn't, you don't need to work on the print function yet. When programming, take it a step at a time.


The i in the for loop in getData() keeps track of how many elements are in table, but it is a local variable to the loop and won't be available to any other parts of the program. You could declare i so it has broader scope or declare a more descriptive variable with more appropriate scope to do that. Initialze that variable to zero before the for loop in getData() and every time through the loop increment it's value by one. This process may need to be modified a bit if there is more than one call to getData() within the program.

Edited by Lerner: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.