What Is Wrong With My Name Finder?

For my C++ class we have a big list of movies, and we have to print out the names when we enter a certain director. Here is my code:

1
2
3
4
5
6
7
8
9
10
11
cout << "Enter Part Of A Director Name: ";
	getline(cin, str);

	for (int i=0; i<numMovies; i++)
	{
		found = films[i].title.find(blank);

		if (found != string::npos)
			printMovie(films[i]);
	}
	


str is a string. When I try to run this part it just jumps into the loop, and prints every movie out. I copy, and pasted this from my professor example, and it works there, but not in mine! What am i doing wrong? In case it is needed here is the code to my entire program.
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
using namespace std;

// Structure Definitions
struct movie
{
	int rank;
	string title;
	int year;
	float boxOffice;
	string rating;
	string director;
};

// Function Prototypes
int loadMovies(movie[]);
void yearRange(movie[], int);
void ratingFinder(movie[], int);
void printMovie(movie);

int main()
{
	movie films[600];
	string str;
	int numMovies;
	unsigned found;
	int choice;

	numMovies = loadMovies(films);
	cout << "Loaded " << numMovies << " movies..." << endl;

	cout << "1. See Movies For A Year Range" << endl;
	cout << "2. See Movies For A Rating" << endl;
	cout << "3. See Movies For A Director" << endl;
	cout << "4. Exit" << endl;
	cout << "Enter The Number For Your Choice: ";
	cin >> choice;

	if (choice == 1)
	{
		yearRange(films, numMovies);
	}
	else if (choice == 2)
	{
		ratingFinder(films, numMovies);
	}
	else if (choice == 3)
	{
	
	cout << "Enter Part Of A Director Name: ";
	getline(cin, str);

	for (int i=0; i<numMovies; i++)
	{
		found = films[i].title.find(blank);

		if (found != string::npos)
			printMovie(films[i]);
	}
	

	}
	else if (choice == 4)
	{
	}


	return 0;
}

int loadMovies(movie m[])
{
	ifstream inFile;
	int count = 0;
	string junk;

	inFile.open("movies.txt");
	if(!inFile)
		cout << "Could Not Open File." << endl;
	else
	{
		cout << "File Opened" << endl;
		
		// Pick Out What We Want:
		inFile >> m[count].rank;
		while(!inFile.eof())
		{
			getline(inFile, junk, '|');
			// Read The Title
			getline(inFile, m[count].title, '|');
			// Read The Year
			inFile >> m[count].year; // Quits At The Decimal Point.
			getline(inFile, junk, '|');
			// Clear The $
			inFile.ignore(); // Ignores The Next Space
			// Read Box Office
			inFile >> m[count].boxOffice; // Read Up To |
			inFile.ignore(); // Ignores The Next |
			// Get The Rating
			getline(inFile, m[count].rating, '|');

			// Skip The Next Three Fields
			getline(inFile, junk, '|');
			getline(inFile, junk, '|');
			getline(inFile, junk, '|');

			// Read The Director
			getline(inFile, m[count].director, '|');

			// Get Rid Of The Last Part
			getline(inFile, junk);

			// Set Up For Next Read
			count++;
			inFile >> m[count].rank;   // Read The First Integer

		}

		inFile.close();
	} 

	return count;
}

void yearRange(movie m[], int numMovies)
{
	int low, high;

	cout << "Enter The Lower Year Number: ";
	cin >> low;
	cout << "Enter The Higher Year Number: ";
	cin >> high;

	for(int i = 0; i < numMovies; i++)
	{
		if(m[i].year >= low && m[i].year <= high)
		{
			printMovie(m[i]);
		}
	}

	return;
}

void ratingFinder(movie m[], int numMovies)
{
	int choice;
	string rating;


	cout << "1. G" << endl;
	cout << "2. PG" << endl;
	cout << "3. PG-13" << endl;
	cout << "4. R " << endl;
	cout << "Enter The Rating You Are Looking For: ";
	cin >> choice;

	if(choice == 1)
	{
		rating = "G";
	}

	else if(choice == 2)
	{
		rating = "PG";
	}
	
	else if(choice == 3)
	{
		rating = "PG-13";
	}

	else if(choice == 4)
	{
		rating = "R";
	}

	for(int i = 0; i < numMovies; i++)
	{
		if(rating == m[i].rating)
			printMovie(m[i]);
	}

	
	return;
}

void printMovie(movie m)
{
	cout << setw(4) << right << m.rank << "  ";
		if (m.title.length() < 30)
			cout << setw(30) << left << m.title;
		else
		{
			for(int i = 0; i < 30; i++)
				cout << m.title[i];
		}

	cout << setw(5) << right << m.year << "  "
		 << setw(8) << right << m.boxOffice << "  " 
		 << setw(6) << left << m.rating
		 << m.director << endl;
	return;
}
When I try to run this part it just jumps into the loop, and prints every movie out. I copy, and pasted this from my professor example, and it works there, but not in mine!

If by "works" you mean "doesn't compile", you might be on to something. blank is not defined anywhere.
It runs, and compiles. It just prints out the entire list of movies, and I did put blank in there somewhere. I changed it from something else which did not work in the first place.
I suspect the reason blank was in there was because you were supposed to replace it with something more appropriate. Like maybe the input you just got from the user?
Ok I got it to work without the getline. Thank you for the help!
Topic archived. No new replies allowed.