Issue with vectors

Vector and String headers are both included. Using namespace std.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
//The following 2 functions setup
//the players inventory and allows the
//player to view it.


int bag_space = 10; //Sets up a maximum bag space for the player

vector <string> inventory(bag_space); //Initialize the array containing the players inventory

void init_inventory(){
	
	for (int x = 0; x < bag_space; x++){
	inventory[x].push_back("Empty");}
	
}

void view_inventory(){

        for (int x = 0; x < bag_space; x++){
	cout << x + 1 << " - " << inventory[x] << endl;}

} 


It returns the following error message:
[Error] invalid conversion from 'const char*' to 'char' [-fpermissive]


Can anyone please help? :( Please say so if I'm not giving sufficient information.

Edit: Nevermind. I changed inventory[x].push_back("Empty"); to inventory[x] = "Empty"; and it works just fine :).
Last edited on
You're pushing an entire C-style string (const char *) into a single char space (the string[x]). It's on line 13. Change it to inventory = "Empty";
* invertory[x] = "Empty"
Topic archived. No new replies allowed.