stl - How to delete several elements from list at once in c++? -


what program follows:

the list contains product information includes product id, name, price etc.

  1. user enters product id
  2. check id if exist in list
  3. so if id matches id in list, shud delete elements of id (product id,name,price etc)

any hints on how it?

you should use struct or class store product information, in single element of list:

struct product {     unsigned int id;     std::string name;     float price; // use int , represent cents };  typedef std::list<product> productlist;   void removeproduct(productlist & productlist, unsigned int id) {     productlist::iterator = productlist.begin();     while (it != productlist.end()) {         if (it->id == id) {             = productlist.erase(it);         }         else ++it;     } } 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -