【问题标题】:How to change file permissions using the Boost library?如何使用 Boost 库更改文件权限?
【发布时间】:2013-05-29 10:04:53
【问题描述】:

如何使用 Boost 库将文件的权限更改为只读?

有一些问题我已经看过了,比如thisthis,但是我还是不知道怎么做,我试过做

boost::filesystem::wpath path = L"abc.txt";
if( boost::filesystem::exists( path ) && boost::filesystem::is_regular_file( path ) )
{
    boost::filesystem::file_status s = boost::filesystem::status( path );
    /* here I need to set file permissitons to READ ONLY for `path` file */
}

有什么想法吗?

【问题讨论】:

  • 那么,有哪些问题呢?你试过什么?
  • @IgorR。更新我的帖子

标签: c++ boost permissions boost-filesystem


【解决方案1】:
#include <boost/filesystem.hpp>

int main()
{
  using namespace boost::filesystem;
  wpath path = L"abc.txt";
  permissions(path, others_read|owner_read);
}

【讨论】:

  • 我正在使用 boost 1.44 并且在 boost::filesystem 命名空间中没有 permissions...
  • @mosg 好吧,您提供的链接指向 1.49 的文档。如果您使用早期版本,您很可能无法设置权限。但是请注意,1.44 大约是 3 岁...
  • 是的,是我的错,没有提到 boost 版本。还是谢谢!
【解决方案2】:

使用 boost 1.55,在 Windows 下,以下工作:

permissions(file_path, add_perms|owner_write|group_write|others_write);

【讨论】:

    猜你喜欢
    • 2017-01-10
    • 2012-04-04
    • 1970-01-01
    • 1970-01-01
    • 2011-12-30
    • 1970-01-01
    • 1970-01-01
    • 2011-02-27
    • 2017-04-06
    相关资源
    最近更新 更多