boost库filesystem使用问题

本文探讨了使用 Boost 库中的 FileSystem 组件时遇到的一个问题:尝试清空 path 对象时编译器报告错误。文章详细展示了错误信息,并通过源代码示例解释了为何会出现该错误。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#include <boost/filesystem.hpp>
#include <iostream>
#include <string>
#include <stdlib.h>


int main(int argc, char* argv[])
{
  boost::filesystem::path my_path("/root/yijunjun.txt");
  my_path.clear();
  return 0;
}

makefile文件部分:
filesystem:main.o
    g++ -o $@ $< -lboost_filesystem-gcc42-mt
main.o:main.cpp
    g++ -c $<
clean:
    rm -rf *.o
    rm -rf filesystem

编译出错提示:
 error: ‘struct boost::filesystem::path’ has no member named ‘clear'

其它函数没有这样的错误,这个错误有两点比较奇怪。
第一:
在其文档中明明的如此说明
class basic_path:
basic_path& operator/=(const basic_path& rhs);
basic_path& operator/=(const string_type& s);
basic_path& operator/=(const value_type* s);
template <class InputIterator>
basic_path& append(InputIterator first, InputIterator last);

void clear();
void swap( basic_path & rhs );

basic_path& remove_leaf();
第二:
明明
typedef basic_path<std::string, path_traits>    path;

应该来说是一个类类型,怎么会提示struct呢?

特此记下。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值