
Answers 259
But with C++ you must cast to get the correct results in this case:
out_file << static_cast<char>(ch);
Answer 100: The program outputs:
First: second Second: second
The problem is that the
readdir
returns a pointer to static data. This data is
owned by
readdir
and overwritten by subsequent calls.
So what happens is this: We call
scan_dir
and set
first_ptr
to point to the
string
first
. That’s what we want, but the array containing the name is static
and when we call
readdir
again, it uses the same buffer to store the name
second
. So now
first_ptr
points to
second
, which is the cause of our trouble.
Answer 101: In the base class destructor ...