简介
- BOOST常用编程技巧
boost::filesystem::path 转 std::string
要将 boost::filesystem::path
转换为 std::string
,你可以使用 boost::filesystem::path
对象的 string()
成员函数。这个函数返回一个表示路径的 std::string
。以下是一个示例:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <boost/filesystem.hpp>
#include <iostream>
#include <string>
int main() {
boost::filesystem::path filePath("/path/to/your/file.txt");
// 将 boost::filesystem::path 转换为 std::string
std::string filePathString = filePath.string();
// 打印转换后的 std::string
std::cout << "File path as string: " << filePathString << std::endl;
return 0;
}
在这个示例中,filePath.string()
函数将 boost::filesystem::path
对象 filePath
转换为一个 std::string
,然后我们将其打印出来。