Reading text file problems

http://www2.cs.uidaho.edu/~bruceb/cs121/Assignments/tvDB.txt

So I need help reading this text file into a Node. I want to put the title of the show as a string, the years as two different integers, a genre as a string, and the actors in a string array. I just have trouble placing the specific text into the proper places. I've tried using getchar or getline but I haven't come to any success. I'm not asking for an entire thing of code but just a point in the right direction would definitely help.



Hello @SeanKeisuke,

Because i don't know what you have so far,
i think that this code can help to you to
get all string lines from your file;


Jake and the Fatman (1987-1992)
Drama
[some link] <-Edited 
William Conrad
Joe Penny
Alan Campbell

Kung Fu: The Legend Continues (1993-1997)
Adventure
[some link] <-Edited 
David Carradine
Chris Potter
Richard Anderson
Kim Chan

Matlock (1986-1995)
Mystery
[some link] <-Edited 
Andy Griffith
Nancy Stafford
Julie Sommars
Clarence Gilyard Jr.
Kene Holliday



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <iostream>
#include <string>
#include <vector>
#include <fstream>



int main(int argc, const char * argv[]) {
    
    std::ifstream ifile("/Users/Eyenrique/Documents/test_rfm_1/test_rfm_1/records.txt");
    std::string text = "";
    
    if(ifile)
    {
        
        while(std::getline(ifile,text))
        {
            std::cout<<text <<'\n';
        }
        
    }else
    {
        return EXIT_FAILURE;
    }
    
       return 0;
}


EDIT: Real links to movies.. wt??.. Computer science department...
Last edited on
The file you linked is not accessible, probably the server is too busy.
The browser shows: The connection has timed out
So I don't know how the input file looks like. Can you just copy and paste a few lines here?

I would create a struct to hold the data and overload << and >> to input and output it easily.
Are there any restrictions of library functions you can use?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
const int MAX_ACTORS = 5;

struct Show
{
  string title;
  string genre;
  string actors[MAX_ACTORS]; // better to use a vector if allowed
  int year1, // find a meaningful name depending on the meaning
      year2;
};

ostream& operator<<(ostream& os, const Show& show)
{
  // place your code here
  return os;
}

istream& operator>>(istream& is, Show& show)
{
  // place your code here
  return is;
}
Topic archived. No new replies allowed.