473,320 Members | 2,110 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

deletion of user defined <list>

myset is a user defined class. I am trying to delete the element using "remove" but it gives an error

for (list<myset>::iterator i=a[v].begin(); i!=a[v].end(); i++)
{ cout << *i << " ";
k.remove(*i);}

Please help. Thanks in advance
Jul 5 '21 #1
2 2992
dev7060
630 Expert 512MB
myset is a user defined class. I am trying to delete the element using "remove" but it gives an error

Expand|Select|Wrap|Line Numbers
  1. for (list<myset>::iterator i=a[v].begin(); i!=a[v].end(); i++)
  2. { cout << *i << " ";
  3. k.remove(*i);}
Please help. Thanks in advance
- What error?
- What's a[v]?
- What's with the usage of *i?
- What's k?
- 'remove()' removes all the elements in the list container that are equal to the value passed in the argument. But it probably needs an operator== implementation to know how to compare the two objects.
Jul 6 '21 #2
iamkajal
2 2Bits
you should try this

/ C++ code to demonstrate the working of erase()

Expand|Select|Wrap|Line Numbers
  1. #include<iostream>
  2. #include<list> // for list operations
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     // initializing list of integers
  8.     list<int> list1={10,15,20,25,30,35};
  9.  
  10.     // declaring list iterators
  11.     list<int>::iterator it = list1.begin();
  12.     list<int>::iterator it1 = list1.begin();
  13.  
  14.     // incrementing the positions of iterators
  15.     advance(it,2);
  16.     advance(it1,5);
  17.  
  18.     // printing original list
  19.     cout << "The original list is : ";
  20.     for (list<int>::iterator i=list1.begin(); i!=list1.end(); i++)
  21.        cout << *i << " ";
  22.  
  23.     cout << endl;
  24.  
  25.     // using erase() to erase single element
  26.     // erases 20
  27.     list1.erase(it);
  28.  
  29.     // list after deletion 1 element
  30.     cout << "The list after deleting 1 element using erase() : ";
  31.     for (list<int>::iterator i=list1.begin(); i!=list1.end(); i++)
  32.        cout << *i << " ";
  33.  
  34.     cout << endl;
  35.  
  36.     it = list1.begin();
  37.  
  38.     // incrementing the positions of iterators
  39.     advance(it,2);
  40.  
  41.     // using erase() to erase multiple elements
  42.     // erases 25,30
  43.     list1.erase(it,it1);
  44.  
  45.     // list after deletion of multiple elements
  46.     cout << "The list after deleting multiple elements using erase() : ";
  47.     for (list<int>::iterator i=list1.begin(); i!=list1.end(); i++)
  48.        cout << *i << " ";
  49.  
  50.     cout << endl;
  51.  
  52.  
  53. }
Jul 7 '21 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Shailesh | last post by:
Hello, I want to set up some USER DEFINED METRICS in 10g. The restriction with USER DEFINED METRICS, is the query (or function ) monitoring that metrics should return only 1 value. I want to...
13
by: dawatson833 | last post by:
I have several stored procedures with parameters that are defined with user defined data types. The time it takes to run the procedures can take 10 - 50 seconds depending on the procedure. If I...
2
by: David Emme | last post by:
Access 97 I have a number of SELECT statements which contain references to user-defined VBA functions. These typically work as expected, but occasionally, on one user's machine or another,...
3
by: chreo | last post by:
I have user-defined function in MSSQL which returns Table (with 10 columns) (sorry for Polish names) CREATE FUNCTION PACZKI_Z_AKCJI (@AKCJA_ID int) RETURNS TABLE RETURN SELECT TOP 100...
1
by: abcabcabc | last post by:
I write an application which can let user define own date format to input, How to convert the date string to date value with end-user defined date format? Example, User Defined Date Format as...
17
by: Steve R. Hastings | last post by:
I have been studying Python recently, and I read a comment on one web page that said something like "the people using Python for heavy math really wish they could define their own operators". The...
3
by: Hallvard B Furuseth | last post by:
I'm wondering how to design this: An API to let a request/response LDAP server be configured so a user-defined Python module can handle and/or modify some or all incoming operations, and later...
0
by: tony | last post by:
Hello! For some month ago I created a project using template Window Control Library. From this template I created a user control(DLL) that I have in the toolbox and can drag it into a window...
6
by: JLupear | last post by:
I have written a code (a translation of my first one) that is not working. I did a user defined function that is used on 'onsubmit'. It should total the value from the form selections and...
0
by: Hello World | last post by:
How do you find if the user defined modules are imported? This tries to see if it is imported ("-" is for easier to read): Loaded modules: - tokenize: LPAR,PseudoToken,ENDMARKER -...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.