List of marked items:
1) You need to allocate space for n characters, where n is the number of characters in the string, plus room for the final zero byte.
2) Then you changed the stream to point to another line. Therefore, you must use the delete[] function for the variable to be created using new[] .
But why are you fooling new and delete for character data? Why not just use std::string instead of the "C" functions? It's amazing why many don't do the easiest thing:
#include <cstdio>
No need for new[] , delete[] , strcpy() , etc.
Use strlen() . Even better, do not use char* and use std::string for string data.
source share