vector

How can I get new vector from matching elements of in this example vector and array?
Thanks!

1
2
3
4
5
6
7
8
 for (vector<string>::iterator   i = ingredients.begin();
                                    i!= ingredients.end();
                                    ++i)
    { for (int b=0;b<3;b++)
    {if (*i==pizza[b])
        {
            *i.push_back (pizzamatch);
        }}}
closed account (SECMoG1T)
Do you mean creating a new vector to contain matching elements, if so

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
 /// create a vector
   vector<string> match;
 
  for (vector<string>::iterator i = ingredients.begin(); i!= ingredients.end(); i++) 
    { 
        for (int b=0;b<3;b++)
            {
                 if   (*i==pizza[b]) 
                    {
                         ///  *i.push_back (pizzamatch); // what is this pizzamatch , you can't call push_back on an 
                         ///  iterator
                         match.push_back (*i);
                     }
             }
     }

     You can now  use vector match for what you intended
Not enough information shown, What is pizzamatch?

Line 7: You're trying to push pizzamatch (whatever that is) onto the string pointed at by your iterator *i.

Assuming pizzamatch is vector<string> pizzamatch;, then line 7 should be as follows:

 
  pizzamatch.push_back(*i);



I apologize for not making myself clear, but you assumed right, thank you for your answers!
Topic archived. No new replies allowed.