c++ - Boost::filesystem::is_symlink() 不起作用

标签 c++ boost symlink boost-filesystem

当我启动这段代码时,它说每个文件都是常规的,甚至是符号链接(symbolic link):

cout<<boost::filesystem::is_symlink(boost::filesystem::status("link-name"))<<endl;

谁知道为什么? (编译过程中没有警告也没有错误) 该链接是使用以下命令创建的:

ln -s file-name link-name

并且 ls 命令说它是一个链接:

ls -l link-name
lrwxrwxrwx 1 myname mygroup 8 juil. 23 14:12 link-name -> file-name

谢谢!

编辑:另一方面,函数 boost::filesystem::is_regular_file 总是返回 true。

最佳答案

您应该使用 symlink_status(const path& p),如 boost reference documentation .

file_status symlink_status(const path& p);

Returns: Same as status(), except that if the attributes indicate a symbolic link, as if by ISO/IEC 9945 S_ISLNK(), return file_status(symlink_file).

关于c++ - Boost::filesystem::is_symlink() 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24911154/

相关文章:

c++ - 在类定义之外为模板类定义 operator[]()(数组订阅)

c++ - 在 C++ 中编写自定义编译命令时的快捷方式。

c++ - 使用 tcpdump 捕获服务器-客户端通信

c++ - spirit boost x3 : compound attribute compile time error (enum class)

c++ - 在 boost-build (b2) 项目中构建基于 makefile 的依赖项

macos - 如何删除符号链接(symbolic link)?

linux - 创建一个名称为 'dir/file' 指向 'target_file' 的符号链接(symbolic link)?

Python 2.7.3 : Copying symlinks, 但不跟

c++ - 具有 protected 派生成员的 CRTP

c++ - 使用 MSVC 14.0 (VS 2015) 编译 Boost 时编译器版本未知