Using classes
The Resource Acquisition Is Initialization technique is useful for managing resources provided by other libraries, such as the C Runtime Library or the Windows SDK. It simplifies your code because you do not have to think about where a resource handle will go out of scope and provide clean-up code at every point. If the clean-up code is complicated, it is typical in C code to see it put at the end of a function and every exit point in the function will have a goto
jump to that code. This results in messy code. In this example, we will wrap the C files functions with a class, so that the lifetime of the file handle is maintained automatically.
The C runtime _findfirst
and _findnext
functions allow you to search for a file or directory that matches a pattern (including wildcard symbols). The _findfirst
function returns an intptr_t
, which is relevant to just that search and this is passed to the _findnext
function to get subsequent values. This intptr_t
is an opaque pointer to...