Thank you for replying.

I tried this way too. if i open the file like
outfile.open ("test.txt",ios:ut|ios::ate);
or
outfile.open ("test.txt",ios::ate);

it overwrites the contents of existing file and displays just the sam in the file.

Any other suggestions are welcome.

Thansks.