RAII is arguably one of the more notable differences between C and C++. RAII sets the foundation and design patterns for the entire C++ library, and has been the inspiration for countless other languages. This simple concept provides C++ with an unmatched level of safety when compared to C, and this concept will be leveraged throughout this book when C and POSIX must be used in place of C++ (for example, when a C++ alternative either doesn't exist or is incomplete).
The idea behind RAII is simple. If a resource is allocated, it is allocated during the construction of an object, and when the object is destroyed, the resource is released. To accomplish this, RAII leverages the construction and destruction features of C++, for example:
#include <iostream>
class myclass
{
public:
myclass()
{
std::cout << "...