maclem8223
[H]ard|Gawd
- Joined
- Oct 28, 2013
- Messages
- 1,849
Hello all,
I'm not sure on the code formatting for [H] so I apologize in advance (trying to use
The function to create the list:
and then main.
When I try to cout or cerr head for example:
cout << head->title; I'm not getting anything so I think I'm confused on how to return the head and how to access the list... Any help would be appreciated and I'm sorry about the formatting.
I'm not sure on the code formatting for [H] so I apologize in advance (trying to use
Code:
and [\code] doesn't seem to be working)...I'm in a c++ class where we have a inputfile with movie title, actor, etc. We are to setup a struct and utilize nodes and pointers to establish a linked list and then output to a file the list formatted. The issue I'm having and where I'm not sure I'm fully understanding the concept is in trying to access the list from main.
[B]Here is my header with the struct.
[/B][code]
#ifndef HEADER_H_
#define HEADER_H_
#include <iostream>
#include <iomanip>
#include <string>
#include <ostream>
#include <sstream>
#include <fstream>
#include <cstdlib>
#include <limits>
using namespace std;
struct MovieNode
{
string title;
string actor;
string supActor;
string genre;
string altGenre;
int year;
int rating;
string synop;
MovieNode *next;
};
MovieNode *ReadIntoList(const string INPUT_FILE);
#endif /* HEADER_H_ */
The function to create the list:
Code:
#include "header.h"
MovieNode *ReadIntoList(const string INPUT_FILE)
{
ifstream inFile;
MovieNode *head;
head = NULL;
MovieNode *perPtr;
perPtr = new MovieNode;
inFile.open(INPUT_FILE.c_str());
while(inFile && perPtr != NULL)
{
getline(inFile, perPtr->title);
getline(inFile, perPtr->actor);
getline(inFile, perPtr->supActor);
perPtr -> next = head;
head = perPtr;
perPtr = new MovieNode;
}
inFile.close();
delete perPtr;
perPtr = NULL;
return head;
}
and then main.
Code:
#include "header.h"
int main()
{
//PrintHeaderStream - Outputs the print header to console.
cout << PrintHeaderStream("Maclem", "Intro to Linked Lists",
'A', 4);
string inputFile;
MovieNode *head;
cout << left;
cout << "Please enter the name of the input file you would like to "
"use: ";
getline(cin, inputFile);
head = ReadIntoList(inputFile);
// OutputToFile(head);
return 0;
}
When I try to cout or cerr head for example:
cout << head->title; I'm not getting anything so I think I'm confused on how to return the head and how to access the list... Any help would be appreciated and I'm sorry about the formatting.
Last edited: