I want to update a data file. If a == target then I want it to ignore a b and c and then print the rest of the file to the same file.
Here is my code
Code:
void list(string target)
{
string a, b, c;
ifstream tar("data.txt");
ofstream fout("data.txt");
while(! tar.eof())
{
tar >> a >> b >> c;
if(a != target)
{
fout << a << b << c << endl;
}
}
}
I have tried writing to data2.txt instead of data.txt and it works OK. But when I have it like the above my data.txt file looks like this 6.01347e - 154 with nothing else.
Thanks in advance