Hi, I'm fairly new to vectors and I'm having trouble storing a string in a vector.
I keep getting the errors in lines 51-54: no suitable constructor exist to convert from
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <vector>
#include "Movie.h"
usingnamespace std;
// ------------------------------------------------------
// ----- Constructors -----------------------------------
// ------------------------------------------------------
//Default constructor
Movie::Movie() {}
//Copy Constructors
Movie::Movie(const string& title) {
title_= getTitle();
}
Movie::Movie(const string& title,
const string& director,
Movie_Rating rating,
unsignedint year,
const string& path, const vector<string> & actors) {
title_ = getTitle();
director_ = getDirector();
rating_ = getRating();
year_ = getYear();
url_ = getURL();
actors_ = getActor();
}
// ------------------------------------------------------
// ----- Inspectors -------------------------------------
// ------------------------------------------------------
//gets the movie title
string Movie::getTitle() const {
return title_;
}
//gets the name of the director
string Movie::getDirector() const {
return director_;
}
//gets the rating of the movie
Movie_Rating Movie::getRating() const {
return rating_;
}
//gets the year the movie was released
unsignedint Movie::getYear() const {
return year_;
}
//gets the imdb url of the movie
string Movie::getURL() const {
return url_;
}
//gets the actors of the movie
vector<string> Movie::getActor() const {
return actors_;
}
// ------------------------------------------------------
// ----- Mutators ---------------------------------------
// ------------------------------------------------------
//sets the title of the movie
void Movie::setTitle(const string& title) {
title_ = title;
}
//sets the director of the movie
void Movie::setDirector(const string& director) {
director_ = director;
}
//sets the rating of the movie
void Movie::setRating(Movie_Rating rating) {
rating_ = rating;
}
//sets the year the movie is released
void Movie::setYear(unsignedint year) {
year_ = year;
}
//sets the imdb url of the movie
void Movie::setURL(const string& path) {
url_ = path;
}
//sets the actors of the movie
void Movie::setActor(const vector<string> & actors) {
for ( int i = 0; i < actors.size ( ); ++i ) {
actors_.push_back ( actors[i] );
}
actors_ = actors;
}
//converts the enum Movie_Rating to string type
string Movie::convert_rating(Movie_Rating r){
switch (r) {
case PG:
return"PG";
break;
case R:
return"R";
break;
case G:
return"G";
break;
case PG13:
return"PG-13";
break;
case NC17:
return"NC-17";
break;
case NR:
return"NR";
break;
default:
cout << "Error in movie_rating() function" << endl;
exit (1);
}
}
//----------------------------------------------------------------------------
//----- Facilitators ---------------------------------------------------------
//----------------------------------------------------------------------------
//prints the output of the program
string Movie::toString ()
{
//---------------------------------------------------------------------
// The ostringstream type allows output to be directed to
// a string in the same style as usually done with a stream.
//---------------------------------------------------------------------
vector <string> :: iterator ActorIter;
ostringstream os;
os << "Movie: " << title_ << endl
<< "Director: " << director_ << endl
<< "Year: " << year_ << endl
<< "Rating: " << convert_rating(rating_) << endl
<< "IMDB URL: " << url_ << endl
<< "Actors: ";
for (ActorIter = actors_.begin();
ActorIter != actors_.end();
++ActorIter) {
cout << *ActorIter << endl;
}
string s = os.str();
return s;
}