learning to use string and iterators,

and i am having trouble when i try to replace a string in my vector with a new one
my trouble is starting when trying to replace a string( towards end of code)
i get error with line
myIterator = vectorGameList.push_back("teris");
idk, how i can fix, and why i cannot do it that way i am trying to

thanks alot for help

#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main()
     vector <string> vectorGameList;// defining vector
     vectorGameList.push_back("donkey kong");// assigning the initial games on the list
     vectorGameList.push_back("super mario");
     int i;
     vector<string>::iterator myIterator;
     vector<string>::const_iterator iter;
       cout << " The games on your list are:\n\n ";// list games
       for (iter = vectorGameList.begin(); iter != vectorGameList.end(); ++iter )// for loop to list using iter
           cout << *iter << endl;
   cout << " \n\nreplacing 3rd one on the list. " << endl;// this is my trouble i want to replace tetris with pacman but get error when try
   myIterator = vectorGameList.push_back("teris"); 
   *myIterator = "pacman";
   cout << "\nyour new list: " << endl;  
    for (iter = vectorGameList.begin(); iter != vectorGameList.end(); ++iter )
           cout << *iter << endl;

Edited by lgonzo: n/a

6 Years
Discussion Span
Last Post by lgonzo

Take a look at line 30; vector::push_back doesn't actually return anything. Hence, your iterator assignment doesn't work.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.