ok my getData() function reads a text file and stores it into an array called in
ID: 3625775 • Letter: O
Question
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) table[i].adjacentOnes.addRear(x); } } } void printData() Explanation / Answer
hi there
i didn`t get what u want exactly but if u want outbut the data stored in the array to the screen a for loop can do it
i have this function i made myself once don`t know if this can give u an idea for what u want do it the function takes a file_name as a parameter and open the file with a ifstream variable gets the data and print them reversely by words not letters i know that`s not what u r looking for but if u can explain more what u r looking for maybe i can help
void print_reverse(string filename)
{
string a[100],a2[100];
string line;
int i=0,s=0;
cout<<"The sentences in reverse order: ";
myfile.open(filename.c_str());
//the next tow steps to make the pointer return to the beginning of the fle in case u entered the file before
myfile.clear();
myfile.seekg(ios::beg);
while (!myfile.eof())
{
getline(myfile,line);
a[i]=line;
istringstream iss(line);
do
{
string word;
iss >> word;
a2[s]=word;
s++;
} while (iss);
for (int i=s-1; i>=0; i--)
cout<<a2[i]<<' ';
cout<<endl;
s=0;
i++;
}
cout<<" ";
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.