Click here to Skip to main content
15,910,277 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have to perform deletion so how can i delete a particular element of vector list?

What I have tried:

C++
#include<iostream>
#include<cstdlib>
#include<vector>

using namespace std;
class StoryBoard
{
private:

string title;
string text;
string tag;
public:

StoryBoard(){}

StoryBoard(string name,string remark,string identifier)

{

title = name;
text = remark;
tag = identifier;

}
void printStory()
{
cout<<"Title : "<<title<<endl;
cout<<"text :="" "<<text<<endl;
cout<<"tag="" "<<tag<<endl<<endl;
}
};
int="" main()
{
int="" position,="" choice;
string="" name,="" key,="" remark,="" identifier;
vector<storyboard="" *=""> vec;
while(1)
{
cout<<"Menu :\n\t1.Add a new note on storyboard.\n\t2.Display all the notes present on the Storyboard.\n\t3.Delete a note.\n\t4.Exit"<<endl;
cout<<"select your="" choice="" and="" please="" enter:="" ";
cin="">>choice;
switch(choice)
{
case 1:
     {                                                          //Adding a new note
cout<<"\n\tEnter the Title of your Note : ";
cin.ignore();
getline(cin, name);
cout<<"\n\tEnter Some Text in Your Note : ";
getline(cin, remark);
cout<<"\n\tEnter any Tag for Your Note : ";
cin>>identifier;
vec.push_back(new StoryBoard(name,remark,identifier));
break;}
case 2:
    {                                                                                                   //Display all notes
int i=0;
cout<<endl<<endl<<"list of="" all="" notes="" :="" "<<endl;
vector<storyboard="" *="">::iterator itr;
StoryBoard *sb;

for(itr=vec.begin();itr!=vec.end();itr++)
{

cout<<"StoryBoard "<<i+1<<" --=""> "<<endl;
sb=*itr;
sb->printStory();
cout<
Posted
Updated 1-Apr-20 5:01am
v3
Comments
CPallini 1-Apr-20 4:37am    
What issue? Simply implement them.

We are more than willing to help those that are stuck: but that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.
All you have done so far is post your homework question and what looks like what you handed in for the last exercise.

We need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.
 
Share this answer
 
Quote:
how can i delete a particular element of vector list?

You can use vector::erase - C++ Reference[^] to remove an element from a vector. Note that this invalidates all iterators referring to that position or beyond (that might include your_vector.end() in case you store that in a variable).

All you need is the iterator referring to the element you want to erase.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900