storing strings to a vector

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

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
#include <iostream>
#include <string>
#include <vector>
#include "Movie.h"

using namespace std;

vector <string> movieActors;

void promptForMovie(Movie & myMovie);
// prompts the user the user for movie title and returns a Movie object to the calling program
// @param myMovie - takes the movie attribute that the user entered

void printMovie(Movie & myMovie);
// sets and prints the movie attribute


//-------------------------------------
//Main program ------------------------
//-------------------------------------

int main () {
	Movie movie;

	promptForMovie(movie);

	printMovie(movie);
	
	return 0; //program done
}

//------------------------------------------------------
//Subprograms ------------------------------------------
//------------------------------------------------------

void promptForMovie(Movie & myMovie) {
	cout << "Enter movie attribute: ";
	string mInfo = " ";
	getline(cin, mInfo);
	myMovie.setTitle(mInfo);
}

void printMovie(Movie & myMovie) {
	if (myMovie.getTitle() == "The Dark Knight") {

	myMovie.setTitle("The Dark Knight");
	myMovie.setDirector("Christopher Nolan");
	myMovie.setYear(2008);
	myMovie.setRating(PG13);
	myMovie.setURL("http://www.imdb.com/title/tt0468569/");
	myMovie.setActor("Christian Bale") ;   
	myMovie.setActor("Heath Ledger") ;
	myMovie.setActor("Aaron Eckhart") ;
	myMovie.setActor("Gary Oldman") ;          

	cout << myMovie.toString() << endl;    //prints the movie attributes  
	}


	else if (myMovie.getTitle() == "Django Unchained") {

	myMovie.setTitle("Django Unchained");
	myMovie.setDirector("Quentin Tarantino");
	myMovie.setYear(2012);
	myMovie.setRating(R);
	myMovie.setURL("http://www.imdb.com/title/tt1853728/");
	
	cout << myMovie.toString() << endl;    //prints the movie attributes  
	}

	else if (myMovie.getTitle() == "Maleficent") {

	myMovie.setTitle("Maleficent");
	myMovie.setDirector("Robert Stromberg");
	myMovie.setYear(2014);
	myMovie.setRating(PG);
	myMovie.setURL("http://www.imdb.com/title/tt1587310/");
	
	cout << myMovie.toString() << endl;    //prints the movie attributes  
	}

	else if (myMovie.getTitle() == "The Lion King") {

	myMovie.setTitle("The Lion King");   
	myMovie.setDirector("Roger Allers, Rob Minkoff");
	myMovie.setYear(1994);
	myMovie.setRating(G);
	myMovie.setURL("http://www.imdb.com/title/tt0110357/");

	cout << myMovie.toString() << endl;    //prints the movie attributes  
	}
	
	else if (myMovie.getTitle() == "American Psycho" ) {

	myMovie.setTitle("American Psycho");
	myMovie.setDirector("Mary Harron");
	myMovie.setYear(2000);
	myMovie.setRating(NC17);
	myMovie.setURL("http://www.imdb.com/title/tt0144084/");
	
	cout << myMovie.toString() << endl;    //prints the movie attributes  
	}
}


Can someone give me advice on how I can correctly store several actor names so that it will print like:
i.e.

Movie: The Dark Knight
Director: Christopher Nolan
Year: 2008
Rating: PG-13
Actors: Christian Bale
Heath Ledger
Gary Oldman
Aaron Eckhart

Oh and here's the method for the .h file:
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
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <vector>
#include "Movie.h"

using namespace 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,
			      unsigned int 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
		unsigned int 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(unsigned int 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;
		}
anyone?
The setActor() function takes a vector of strings, but you're trying to call it with just a string.
how do I call it as a vector of strings and not just a string?

would it be like
myMovie.setActor(myMovie.push_back("Christian Bale"));
change
1
2
3
4
5
6
7
void Movie::setActor(const vector<string> & actors)
{
    for ( int i = 0; i < actors.size ( ); ++i )
        actors_.push_back ( actors[i] );

    actors_ = actors;
}

to
1
2
3
4
void Movie::setActor ( const string & actor )
{
        actors_.push_back ( actor );
}

You might want to change the function name to addActor as well.
Worked like a charm. Thanks very much!
Topic archived. No new replies allowed.