473,394 Members | 1,226 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,394 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 2996
dev7060
636 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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.