storing user input into array for delete

Hi,this is my 1st C++ coding and i have some problems. the user will input eg Veg,and after that it will store into data.txt.
After that the user can type in "veg" and it will store into an array to be deleted.What i am trying now is to create a temp data to store the value.I think i am missing some codes.Can i advise for help?

ofstream data,tdata;
string temp[100],ItemDesc;

{
data.open("data.txt");
tdata.open("tempdata.txt");
cout <<"Remove\n";
cin >> temp[100];
temp[100] >> DeleteItem;

while (!data.eof())
{
if (temp[100] != DeleteItem)

tdata << temp[100] << endl;
}
tdata.close();
data.close();
remove("data.txt");
rename("tempdata.txt","data.txt");


}
This

string temp[100]

creates an array of 100 strings, not a string with space for 100 characters; I think you've confused C++ strings with c-style char arrays. In this code, you are only using one of the strings you created; the hundredth one.

DeleteItem

What is this? It's not defined in the code chunk that you provided.
Last edited on
i forgot to add DeleteItem string up there.
i intend to store the user input into temp array,from there it will search data.txt and be pulled out from data.txt to be deleted
If you want to store the user input in an array, you should consider making it an array of char, rather than an array of string.

I think you should discard the array completely and just use a string.

1
2
string temp;
cin >> temp;

Topic archived. No new replies allowed.