very new to c++ . have an assignment when am to input some information about an item and write to a file . Have succesfully done that but now i i dont know how to delete a line of entry from the text file and save it . look at so many ways the one method i saw deletes the whole contents of the file which is not what i need ,
the delete function had to just delete the word typed and delete all the entries on that line . not the entire contents of the file
void deletefind() {
string deleteline;
string line;
ifstream in("Coreship.txt");
if (!in.is_open()) {
cout << "Input file failed to open\n";
}
ofstream out("outfile.txt");
cout << "Please Select the Vessel you would like to remove" << endl;
cin >> deleteline;
while (getline(in, deleteline)) {
if (line != deleteline)
out << line << endl;
}
in.close();
out.close();
remove("Coreship.txt");
rename("outfile.txt", "Coreship.txt");
cout << "\nChanges has Successfully been made...... Data Saved\n" << endl;