auto file_closer = [](int* pfd) { close(*pfd); };
int fd = open("a.txt", O_WRONLY|O_CREAT, 0666);
unique_ptr<int, decltype(file_closer)> raii_fd (&fd, file_closer);
// using fd
Use unique_ptr to RAII your file objects
最新推荐文章于 2025-06-04 18:30:00 发布