I have the following simple code. It consists of an array with 4 items. It first displays the items, then asks the user to delete as many as they want.(with an option to continue without deleting anything). After the user has removed or not removed items, the program will display the new update list.
i do not know how to delete specific things from my array. this is the code: (it works until you delete something, if you choose to not delete anything it works fine)
#include <iostream>
#include <string>
using namespace std;
class test
{
public:
int del;
string word;
void one(test array[]);
};
void test::one(test array[]){
array[0].word="0 cat";
array[1].word="1 dog";
array[2].word="2 bird";
array[3].word="3 fish";
for(int i=0; i<4; i++){
cout<<array[i].word<<endl;
}
cout<<"DELETE NOW. input 4 to confirm/finish"<<endl;
for(int i=0; i<3; i++){
cin>>del;
if(del==4)
break;
delete &array[del].word;
}
for(int i=0; i<4; i++){
cout<<array[i].word<<endl;
}
}
int main(){
test array[10];
test tes;
tes.one(array);
system("pause");
return 0;
}
any help is greatly appreciated