Error with Vectors

i am going through this intro to C++ book and the end of chapter challenge is to make a vector in which you can add, search and display game titles help in a vector. I managed to get this far, but i get this nasty huge error with the compiler and it does not point to the line that gives the error. I (think) i found the problem at line 46:49 (the search command), but I'm not sure.

I am at a total loss, any ideas from the pros out there??

Thanks in advance....

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
// Game List Depot
// The List of favorite games
// ((Excersise from c++ book))

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iterator>
#include <cctype>

using namespace std;

int main()
{
    vector<string> games;           ///Games vector container
    games.push_back("Devil May Cry");    //Few Seed games, classics....
    games.push_back("Super mario 3");
    
    int choice; //iter = 1;
    const int iter_c = 1;
    string search;
        
    cout<<"*******************************\nWelcome to the Game List Depot\n*******************************\n\nWhat would you like to do?";
    cout<<"\n\t 1.) Add a game \n\t 2.) Search for a Game \n\t 3.) Show all games in Database \n\t 0.) Exit\n\n ->";
    cin>>choice;
    do{
    if(choice == 1){
    //Add
        string input;
        cout<<"What is the Game title you wish to add?\n";
        cin>>input;
        int k = 1;
        do {
            cin >> input;
            games.push_back (input);
            k = 0;
            } while (k);
        cout << "There are " << int(games.size()) << " games in the Database.\n";
        
  
    }else if(choice == 2){ 
    //Search
        cout<<"What game do you seek?\n";
        cin>>search;
        find (games.begin(), games.end(), iter_c);
            for (; games.begin() != games.end(); ++games.begin()) {
            if (*games.begin() == search) {
                cout << "Game found!!\n" << search << '\n';;
            }else{
            cout<<"Your search was not found!!";
            }
        
        }    
    }else if(choice == 3){      
    //Show all
        for(unsigned int j = 0; j < games.size(); j++){
            cout<<games[j]<<endl;
        }
    
    }else if(choice == 0){
    //exit!!
        cout<<"Thanks for playing!!";
        
    }else{
    //Bad Entry!!!!
        cout<<"Invalid entry! Please try again.";   
    }
    //Will add the delete function later
    }while(choice != 0);
    return 0;
}
Line 47 might not create expected results from the looks of it.

Aceix.
ahh....that Damn search function....

Here was my fix for that
1
2
3
4
5
6
7
8
9
10
11
12
13
//Search
        cout<<"What game do you seek?\n0 Will exit....\n->";
        cin>>search;
        do{
        if(find(games.begin(), games.end(), search) != games.end()){
            cout<<"Match found!\n\t"<<search<<endl;
        }else{
            cout<<"Match not found. Here is a list of Games in the Database:"<<endl;
            for(unsigned int j = 0; j < games.size(); j++){
            cout<<games[j]<<endl;
                }
            }
        }while (search != 0);


Thanks!!
Topic archived. No new replies allowed.