Hi!

I want to ask you why when I write something in file it deletes everything inside.

For ex.

Code:
#include <iostream>
#include <fstream>

using namespace std;
int main()
{
    fstream dat;
    
    dat.open("data.txt",ios::out);
    dat<<"test"<<endl;
    
    dat.close();
    
    dat.open("data.txt",ios::in);
    
    char c[5];
    
    dat>>c;
    
    
    cout<<c<<endl;
    
    
    system("PAUSE");
    
}
In the start I open Notepad, and write "dfsdfdsfsdfsd".

When, dat<<"test"<<endl was executed, everything inside in the file was replaced with single "test".


(2) Why I must delete dynamically allocated memory, shouldn't compiler need to do it?

Thanks in advance.