阅读背景:

boost的filesystem使用示例

来源:互联网 
#include "boost/filesystem.hpp"   // 包含所有需要的 Boost.Filesystem 声明
#include <iostream>               // 使用 std::cout
#include <string>
#include <sstream>
namespace fs = boost::filesystem;

// 宏FSTEST:测试f的成员函数,输出成员函数名和结果
#define FSTEST(x) std::cout << #x##": " << f.x << std::endl

int main(int argc, char **argv)
{
	fs::path f("\folder1\folder2\folder3\filename.ext");

	FSTEST(string());
	FSTEST(root_name());
	FSTEST(root_directory());
	FSTEST(root_path());
	FSTEST(relative_path());
	FSTEST(filename());
	FSTEST(parent_path());
	FSTEST(stem());
	FSTEST(extension());

	FSTEST(replace_extension("new"));
	char buf[] = "hello";
	FSTEST(append(buf, buf + sizeof(buf)));
	FSTEST(remove_filename());

	//
#define  FSTEST2(x) std::cout << #x##": " << fs::x << std::endl
	FSTEST2(initial_path());//得到程序运行时的系统当前路径
	FSTEST2(current_path());//得到系统当前路径

	//要得到EXE文件所在的路径或AppData路径,只能通过调用Win API实现。

	{
		std::cout << "convert to std::string()=>" << fs::initial_path().string();
	}

	return 0;
}#include "boost/filesystem.hpp"   // 包含所有需要的 Bo



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: