Hi I'm trying to read in actors from a file that I got off IMDB and I wanted it to be searchable to whenever the user enters an actors name, the program would output the movies the actor has starred or been associated with. I've gotten the search function to work but the only problem is that it only prints out the first line after the actors name, I want it to print out all movies associated with him whether it be 5 or 10 lines or 50 who knows. This is what I have so far.

#include <iostream>
#include "imdb.h"

using namespace std;

int main()
{
    string name;
    IMDB actor;
    cout << "Enter actors last name, first name: ";
    getline(cin, name);

    actor.setActorsName(name);
    

    actor.load2010File();

    return 0;
}
#include "imdb.h"
#include <fstream>
#include <vector>

IMDB::IMDB()
{
    //ctor
}

IMDB::~IMDB()
{
    //dtor
}
void IMDB::setActorsName(string actorsName)
    {name = actorsName;}

void IMDB::load2010File()
{
    string line;
    
        // opens file
    ifstream inputFile("actors.2010.list", ios::in);
        // test if file exists
    if(!inputFile)
        cout << "Error opening actors.2010.list";
    bool next = false;
    while(!inputFile.eof())
    {
        getline(inputFile, line);

        if(next)
        {
            getline(inputFile, line, '(');  // parsed once a '(' is encountered 
            cout << line;
            break;
        }
        

        if(line == name)
        {
            cout << "yes " << name << endl;
            next = true;
            continue;
        }

    }
    inputFile.close();
}

any help would be appreciated.

beware of loops controlled with return type of eof(). If everything is set up right, it is okay, but it's easy to get caught in at least a potential bug that is readily avoidable.

There are three files...the first one posted is the main.cpp file, the second is the imdb.cpp file and the following is the imdb.h header file

#ifndef IMDB_H
#define IMDB_H

#include<iostream>
using namespace std;
class IMDB
{
    private:
        string name;
        string movie;
    public:
        IMDB();
        ~IMDB();

        void load2010File();

        void setActorsName(string actorsName);
       
};


#endif // IMDB_H

Here is an example of what the text looks like:

5 Browns, The
	The 5 Browns: Live in Concert (2010)  [Themselves]

50 Cent
	13 (2010)  (as Curtis Jackson)  [Jimmy]  <38>
	Caught in the Crossfire (2010)  (as Curtis '50 Cent' Jackson)  [Tino]  <3>
	Gun (2010)  (as Curtis Jackson)  [Rich]  <1>
	Jekyll and Hyde (2010) {{SUSPENDED}}
	Morning Glory (2010)  (as Curtis '50 Cent' Jackson)  [Himself]  <59>
	The Best of: BlacksInActionTV.Com (2010)  [Himself]
	The Ski Mask Way (2010) {{SUSPENDED}}  [Seven]
	Twelve (2010)  (as Curtis Jackson)  [Lionel]  <4>
	"Conan" (2010) {Octoparrot vs. Megakitten (#1.47)}  [Himself]  <2>

666, Zapata
	La hora cero (2010)  [Parca]  <1>

69, Jyrki
	Timanttikoirien vuosi 1984 (2010)  [Himself]  <24>
	"Rock-Suomi" (2010) {Amerikan ääni (#1.4)}  [Himself]  <19>
	"Rock-Suomi" (2010) {Idolit (#1.5)}  [Himself]  <15>

6Cyclemind
	"Pilipinas Got Talent" (2010) {Grand Finals: Results Night (#2.35)}  [Themselves - Performer]  <21>

I want it so that whenever I look up the actors name only the movies associated with that actor will appear. As of right now only the first movie appears.

Is this pattern correct?
1) if the line starts with a numeral, then it is a new artist,
2) if the line starts with a tab, then it is movie associated with the most recent actor found
3) if the line starts with space, then it is and empty line.

If so, then you should be able to come up with a scheme to differentiate what type of line each line is once you've read it in and you can use that information to search for an artist and determine if it is the correct artist. If it is the correct artist then display each line starting with a tab and stop with the first line that starts with a space. If it's not the correct artist then ignore all the subsequent lines until you find the next artist line.

read in a line
 if an artist line
  extract artist from line
  if correct artist
    read in a line
      if line starts with tab
        display movie information
      else
         stop this inner loop
This article has been dead for over six months. Start a new discussion instead.