We're doing the "How Close to Kevin Bacon" problem in class. To do it, we are building a graph using maps and sets. I'm still new to C++, and am having problems with the very beginning (reading the file). Here is a sample line from the file:
43: The Richard Petty Story (1974)/McGavin, Darren/Beery Jr., Noah/Petty, Richard (I)/Jalbert, Pierre/Jones, L.Q./Whittington, Jerry (I)/Browne, Kathie
Where the first part is the title of the movie, and everything else is a list of the actors (all delimited by "/"). Apparently, the movie should just be a string, while all the actors should be added to a set. Then, they will all be added to the map together. Here is the header file provided:
Code:
#ifndef GRAPH_H
#define GRAPH_H
#include <string>
#include <map>
#include <set>
using namespace std;
class Graph {
public:
Graph();
Graph(string);
Graph(const Graph& orig);
virtual ~Graph();
void addEdge(string v, string w);
void adjacentTo(string,
set<string>::const_iterator &,
set<string>::const_iterator &);
void vertices(map<string,set<string> >::const_iterator &,
map<string,set<string> >::const_iterator &);
private:
map <string, set<string> > ST;
};
#endif
/* GRAPH_H */
Apparently, it should only be around two lines total, which makes me feel fairly stupid, to be honest. I've used ifstream a little, and am pretty sure it will start something like:
Code:
ifstream myFile(str) // str is the name of the file passed in
getLine(myFile, movieName, "/"
But I don't know how to add everything to the set. I'm sure it's probably simple, but I think I've reached max capacity for this semester. Any help would be appreciated. Thanks.