![](/img/trans.png)
[英]C++ BOOST undefined reference to `boost::filesystem::detail::copy_file
[英]C++: Error with Boost Filesystem copy_file
我在使用copy_file函数时遇到了一些麻烦。 我的程序非常简单,我只是尝试将文本文件从一个位置复制到另一个位置。
以下代码显示“调试错误!” 因为调用了abort()。
int main()
{
path src_path = "C:\\src.txt";
path dst_path = "C:\\dst.txt";
cout << "src exists = " << exists( src_path ) << endl; // Prints True
boost::filesystem::copy_file( src_path, dst_path );
return 0;
}
如果我看一下Stackoverflow上的其他一些代码示例,则不会注意到我做错了什么。 我觉得这里缺少明显的东西。
我已经安装了Boost v1.47,并且正在使用Visual C ++ 2010。
我猜目标文件存在。
文档 :
template <class Path1, class Path2> void copy_file(const Path1& from_fp, const Path2& to_fp);
要求 :
Path1::external_string_type
和Path2::external_string_type
是同一类型。效果 :将from_fp解析为的文件的内容和属性复制到to_fp解析为的文件。 抛出 :
basic_filesystem_error<Path>
如果from_fp.empty()
||
to_fp.empty()
||
!exists(from_fp)
||
!is_regular_file(from_fp)
||
exists(to_fp)
像这样的简单测试:
#include <iostream>
#include <boost/filesystem.hpp>
int main()
{
using namespace boost::filesystem;
path src_path = "test.in";
path dst_path = "test.out";
std::cout << "src exists = " << std::boolalpha << exists( src_path ) << std::endl; // Prints true
try
{
boost::filesystem::copy_file( src_path, dst_path );
} catch (const boost::filesystem::filesystem_error& e)
{
std::cerr << "Error: " << e.what() << std::endl;
}
return 0;
}
印刷品:
src exists = true
Error: boost::filesystem::copy_file: File exists: "test.in", "test.out"
在第二次运行:)
我认为如果您使用boost :: filesystem2,则应该使用boost :: filesystem2 :: copy(src_path,dest_path); copy_file应该已被弃用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.