使用 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") ;
谁能告诉我可能是什么问题以及如何解决它?
谢谢:)
最佳答案
确保文件存在并且您有读取该文件的权限:
关于c++ - 无法使用带有boost C++的ubuntu中的完整路径打开文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24205549/