您好,我目前有一个程序可以获取文件位置的完整路径,并放入一个类型为 boost::filesystem2::path 的变量中
我已经查找了如何执行此操作,并发现使用:
string result1 = boost::filesystem::basename (myPath)
将路径转换为字符串,但它只转换文件名(例如,如果路径是“C:\name\bobsAwesomeWordDoc.docx”,它只返回“bobsAwesomeWordDoc”)。
我发现了以下关于如何将整个路径转换为字符串的内容, 但我不知道如何在我的程序中实现它。我尝试了多种方法,但出现转换错误。
const std::string& string( ): This routine returns a copy of the string with which the path was initialized, with formatting per the path grammar rules.
(找到 here)
我试过了:
string result1 = string& (myPath);
以及其他一些变体。
最佳答案
你只需要调用myPath.string()
。
关于c++ - 如何将 boost 路径类型转换为字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4179322/