Use unique_ptr to RAII your file objects
2014-01-25 16:08
351 查看
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
int fd = open("a.txt", O_WRONLY|O_CREAT, 0666);
unique_ptr<int, decltype(file_closer)> raii_fd (&fd, file_closer);
// using fd
相关文章推荐
- Your Podfile has had smart quotes sanitised. To avoid issues in the future, you should not use TextE
- Pods written in Swift can only be integrated as frameworks; add `use_frameworks!` to your Podfile or
- Your Podfile has had smart quotes sanitised. To avoid issues in the future, you should not use TextE
- 使用cocapods报错 [!] Your Podfile has had smart quotes sanitised. To avoid issues in the future, you should not use TextEdit for editing it. If you are not using TextEdit, you should turn off smart quotes
- 94.You plan to move data from a flat file to a table in your database. You decide to use SQL*Loader
- 126.Identify the two situations in which you use the alert log file in your database to check the de
- Your Podfile has had smart quotes sanitised. To avoid issues in the future, you should not use TextE
- [EffectiveC++]item13:Use objects to manage resources(RAII)
- 解决Genymotion模拟器无法使用问题“the file is currupt”,“uable to boot-please use a kernel appropriate for your c
- 异常“check the manual that corresponds to your MySQL server version for the right syntax to use near ”
- How to use script to get all oracle EBS Form name and corresponding fmb file name
- How to use Tower on Mac to control your local Xcode Projects
- How To Use LoadImage() to Read a BMP File(转载)
- HOWTO Use the GCC specs file
- could not find plugin to read objects from file xxx.ive
- [!] Pods written in Swift can only be integrated as frameworks; add `use_frameworks!` to your Podfil
- Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX AVX2
- Unable to boot : please use a kernel appropriate for your cpu
- Tip: Use View.isInEditMode() in your custom views to skip code when shown in Eclipse