In the above code the old buffer is deleted each time and new memory is assigned. But strlen(buffer) returns the size of the string which was before deleting. Also even after 'delete [] buffer' when I stdout buffer I get the entire array which was stored before calling delete. I know I can just set buffer[0] to '\0', but I want to know what is wrong in the above code.
When you called new, a block of 50,000 characters was obtained and it's address was returned and stored in the pointer named buffer.
When you deleted the buffer, you told the memory routines you were no longer using that block of memory, however the pointer named buffer still had the address of that block of memory. Deleting a block of memory does not change any pointers you may have set in your program. However, it is a no-no to reference that memory (as you did in the strlen()) once you've returned that memory.