- Published on
C++ Tidbits
- Authors

- Name
- Yue Zhang
filesystem
std::filesystem::absolute(path)
- This function attempts to convert the provided path into an absolute path.
- If the path is relative, it resolves it relative to the current working directory.
- If the path is already absolute, it simply returns the same path.
Run cmd
std::unique_ptr<FILE, decltype(&_pclose)> pipe(_popen(cmd, "r"), _pclose);
std::unique_ptr<FILE, decltype(&_pclose)>:- This declares a std::unique_ptr that manages a FILE* resource.
- The second template parameter, decltype(&_pclose), specifies the type of the custom deleter function, which is _pclose in this case.
_pcloseis used to close the pipe created by _popen.
_popen(cmd, "r"):_popenis a Microsoft-specific function (used on Windows) that opens a process by creating a pipe, for example, to execute a shell command.- The
cmdis the command to execute. - The
"r"mode specifies that the pipe is opened for reading (standard output of the command).
_pclose:_pcloseis a corresponding function to close the pipe opened by _popen.
std::unique_ptrConstruction:- The
std::unique_ptris initialized with: - The
FILE*pointer returned by_popen. - The
_pclosefunction, which acts as the custom deleter.
- The