R
Rechtfertigung
Guest
I made a function that deletes a line from a .txt file and saves the rest of the text to another file. The problem is that when it deletes the line the new file contains white space where the old line used to be. I debugged the program and noticed that the string variable holding the text that will go into the new file also contains white space. I have tried erasing the white space using erase() but it still remains
Eample: (before) (expected outcome) (actual results)
John 47 69 68 96 Jared 88 76 69 100
Jared 88 76 69 100 Joseph 48 79 60 49 Jared 88 76 69 100
Joseph 48 79 60 49 Joseph 48 79 60 49
code:
void StudentModel::delete_line()
{
ifstream student_info_file;
student_info_file.open("Input.txt");
ofstream temp;
temp.open("temp.txt");
string lines;
string text;
while (getline(student_info_file,lines))
{
text.append(lines);
text.append("\n");
}
text.replace(0,text.find("\n"), "");
temp << text;
student_info_file.close();
temp.close();
remove("Input.txt");
rename("temp.txt", "Input.txt");
}
Recht
Continue reading...
Eample: (before) (expected outcome) (actual results)
John 47 69 68 96 Jared 88 76 69 100
Jared 88 76 69 100 Joseph 48 79 60 49 Jared 88 76 69 100
Joseph 48 79 60 49 Joseph 48 79 60 49
code:
void StudentModel::delete_line()
{
ifstream student_info_file;
student_info_file.open("Input.txt");
ofstream temp;
temp.open("temp.txt");
string lines;
string text;
while (getline(student_info_file,lines))
{
text.append(lines);
text.append("\n");
}
text.replace(0,text.find("\n"), "");
temp << text;
student_info_file.close();
temp.close();
remove("Input.txt");
rename("temp.txt", "Input.txt");
}
Recht
Continue reading...