c++ - 无法使用带有boost C++的ubuntu中的完整路径打开文件

标签 c++ ubuntu boost

使用 ubuntu 使用 boost 库,使用以下代码文件 main.cpp 被打开并被打印但是当我尝试打开一些其他文件时其他位置,它不起作用。

这是代码

std::string line;
boost::filesystem::ifstream file ("main.cpp") ;
if (file.is_open())
{
  while ( getline (file,line) )
  {
    std::cout << line << '\n';
  }
  file.close();
}

else std::cout << "Unable to open file"<< std::endl;

这是我给出的路径,但它不起作用。

boost::filesystem::ifstream file ("/home/0circle/workspace/practice/main.cpp") ;

谁能告诉我可能是什么问题以及如何解决它?

谢谢:)

最佳答案

确保文件存在并且您有读取该文件的权限:

  • 在shell中执行:ls -l/home/0circle/workspace/practice/main.cpp
  • 验证您是否有读取权限(输出的第一列 以前的 shell 命令)。参见 this !
  • 尝试找出失败的原因:参见this !

关于c++ - 无法使用带有boost C++的ubuntu中的完整路径打开文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24205549/

相关文章:

C++:简单递归搜索函数的运行时错误

node.js - z shell 问题,运行别名并得到这个 "zsh: parse error near ` }' "

android - adb 没有看到 android 设备 ubuntu

boost - ptr_map 和指针

c++ - Boost元组和STL vector 编译错误

c++ - 应用于模板类的 CRTP

c++ - 最大化的 MFC 对话框大于监视器

c++ - 如何缩短多个 && 条件

ubuntu - 无法使用 Ubuntu 16.04 登录到 Dockerized SSH 守护程序服务

c++ - Boost::处理管道流和单元测试