C++ Boost找不到文件
我想使用Boost的文件系统函数。我试着C++ Boost找不到文件,c++,boost,directory,cygwin,boost-filesystem,C++,Boost,Directory,Cygwin,Boost Filesystem,我想使用Boost的文件系统函数。我试着 cout << boost::filesystem::file_size(fname.c_str()) << endl; 我确信我的路径是正确的,因为system(“cat file.txt”)可以正常工作。我检查了文件夹是否不是NFS;它是NTFS 我在Windows7机器上的cygwin上使用g++ 编辑:我也试过了 cout << boost::filesystem::file_size(fname); 我尝
cout << boost::filesystem::file_size(fname.c_str()) << endl;
我确信我的路径是正确的,因为system(“cat file.txt”)
可以正常工作。我检查了文件夹是否不是NFS;它是NTFS
我在Windows7机器上的cygwin上使用g++
编辑:我也试过了
cout << boost::filesystem::file_size(fname);
我尝试了不同类型的文件(.txt、.dat、.cpp)
它附带的教程程序tut1.cpp
使用相同的语法,因此我认为这可能是一个编译问题。我试图找到编译tut1.cpp的文件(可能是一个makefile),但运气不好
tut1.cpp如下所示:
// filesystem tut1.cpp ---------------------------------------------------------------//
// Copyright Beman Dawes 2009
// Distributed under the Boost Software License, Version 1.0.
// See http://www.boost.org/LICENSE_1_0.txt
// Library home page: http://www.boost.org/libs/filesystem
#include <iostream>
#include <boost/filesystem.hpp>
using namespace boost::filesystem;
int main(int argc, char* argv[])
{
if (argc < 2)
{
std::cout << "Usage: tut1 path\n";
return 1;
}
std::cout << argv[1] << " " << file_size(argv[1]) << '\n';
return 0;
}
//文件系统tut1.cpp---------------------------------------------------------------//
//版权所有Beman Dawes 2009
//根据Boost软件许可证1.0版发布。
//看http://www.boost.org/LICENSE_1_0.txt
//图书馆主页:http://www.boost.org/libs/filesystem
#包括
#包括
使用名称空间boost::filesystem;
int main(int argc,char*argv[])
{
如果(argc<2)
{
std::cout是fname
一个路径吗?因为这样,只需删除.c_str()
成员调用
可能是访问器函数添加了一些特定于操作系统的引用或转义。()
您可以指定一个std::string,以便在调试器中观察该值。事实上,我后来想到了这个问题;如果没有c\u str()
,错误仍然存在。也许您是对的,我必须使用调试器
boost::filesystem::file_size: Operation not permitted
// filesystem tut1.cpp ---------------------------------------------------------------//
// Copyright Beman Dawes 2009
// Distributed under the Boost Software License, Version 1.0.
// See http://www.boost.org/LICENSE_1_0.txt
// Library home page: http://www.boost.org/libs/filesystem
#include <iostream>
#include <boost/filesystem.hpp>
using namespace boost::filesystem;
int main(int argc, char* argv[])
{
if (argc < 2)
{
std::cout << "Usage: tut1 path\n";
return 1;
}
std::cout << argv[1] << " " << file_size(argv[1]) << '\n';
return 0;
}