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??
// Game List Depot
// The List of favorite games
// ((Excersise from c++ book))
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iterator>
#include <cctype>
usingnamespace 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;
constint 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";
}elseif(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!!";
}
}
}elseif(choice == 3){
//Show all
for(unsignedint j = 0; j < games.size(); j++){
cout<<games[j]<<endl;
}
}elseif(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;
}
//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(unsignedint j = 0; j < games.size(); j++){
cout<<games[j]<<endl;
}
}
}while (search != 0);