boost::filesystem使用实例

#include <boost/filesystem.hpp>

using namespace boost::filesystem;

/////////////////////////////////////////////  

path tpath(current_path());
  cout<<tpath<<endl;
  if (exists(tpath))
  {
   tpath = tpath/"a.txt";
   ofstream outfile(tpath.file_string().c_str());
   if (!outfile)
   {
    cout<<"open file failed!"<<endl;
   }
   outfile<<"luosiming"<<endl;
   outfile.close();
  }
  else
  {
   //目录不存在,创建
   create_directory(tpath);
   tpath = tpath/"a.txt";
   ofstream outfile(tpath.file_string().c_str());
   if (!outfile)
   {
    cout<<"open file failed!"<<endl;
   }
   outfile<<"lishimin"<<endl;
   outfile.close();
  }
  if (is_regular_file(tpath))
  {
   cout<<tpath<<" is regularfile!"<<endl;
   cout<<"file size "<<file_size(tpath)<<" BYTE"<<endl;
   remove(tpath);
  }

你可能感兴趣的:(String,File,Path,include)