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");
     vectorGameList.push_back("tetris");
     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;
         }

Recommended Answers

All 2 Replies

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

able to work out

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.