Help deleting a line from a file (fstream)

Hello everyone. I need to delete a specific line from notas.dat, but instead of that, my code deletes everything but the line i input...

For example.. i have this...

Sucursal Nota
1 2
1 3
1 4
2 1
2 2

I input Sucursal 1, Nota 3.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
void notas::borrar(){
	int num,num2;
	fstream fp,fp2;
	notas nota;
	cout << "Sucursal";cin >> num;cout << "Numero de nota: ";cin >> num2;
	fp.open("notas.dat",ios::in|ios::out);
	fp2.open("temp.dat",ios::out);
	fp.seekg(0,ios::beg);
	    while(fp.read((char*)&nota,sizeof(notas))){
		if((nota.retnumnota()==num2) && (nota.retsucursal()==num)){
        cout << nota.retsucursal() <<" " <<nota.retnumnota() <<" " <<num <<" " << num2;
        system("pause");
        fp2.write((char*)&nota,sizeof(notas));
		}
	}
	fp.close();
    fp2.close();
    remove("notas.dat");
    rename("temp.dat","notas.dat");
    cout<<endl <<"Nota borrada." <<endl;
    system("pause");
}


output

Sucursal Nota
1 3

I suppose the problem is in the condition... but not really sure..

Thanks in advance.
if ( R2D2 && C3PO )
{
  These are the droids that we are looking for.
}
else
{
  Move along!
}


More compactly, when is ! ( Foo && Bar ) true?
I dont understand =(
I suppose the problem is in the condition... but not really sure..

you just need to take the opposite of the condition.

Instead of
1
2
if (condition)
    do something

try
1
2
if (!condition)
    do something


I already tried... but didn't work either... when i do that, it deletes all -sucursal- started with 1

_____________________________-


nvm... i made it work following your idea... thank you very much
Last edited on
Topic archived. No new replies allowed.