如何使用Boost.Filesystem更改当前路径?
How can I change the current path using Boost.Filesystem
启动程序时,我想使用current_path() ("C:workspaceprojects")打印当前路径。然后我希望能够改变路径,让我们说"c:program files",所以当我再次打印current_path()时,我想要打印"c:program files"。像这样
int main()
{
cout << current_path() << endl; // c:workspaceprojects
aFunctionToChangePath("c:program files");
cout << current_path() << endl; // c:program files
}
是否有一个函数在库中,我错过了,所以我可以完成这一点?
int main()
{
cout << current_path() << 'n'; // c:workspaceprojects
current_path("c:\program files");
cout << current_path() << 'n'; // c:program files
}
如果您想更改到另一个目录,那么我建议您尝试一下例子:
boost::filesystem::path full_path( boost::filesystem::current_path() );
std::cout << "Current path is : " << full_path << std::endl;
//system("cd ../"); // change to previous dir -- this is NOT working
chdir("../"); // change to previous dir -- this IS working
boost::filesystem::path new_full_path( boost::filesystem::current_path() );
std::cout << "Current path is : " << new_full_path << std::endl;
相关文章:
- 带有特殊路径部分的"std::filesystem::weakly_canonical"失败
- 在带有尾部斜杠的路径上返回 std::filesystem::create_directories() 的值
- 获取当前正在运行的 exe 名称(不是路径)
- std::filesystem 和 std::experimental::filesystem 之间的路径差异
- 如何获取当前用户的默认RAS电话簿路径?
- 如何使用提升获取当前文件路径?
- 如何在 c++ 中获取当前文件路径?
- 获取自己的可执行文件的当前路径 (C++)
- 从std :: fileSystem ::路径对象的类中退出时的分割故障
- 如何从std :: filesystem ::路径中删除引号
- 如何获取当前图书馆路径
- Boost Filesystem flowly_caronical不会在没有父文件夹的情况下解决相对路径
- 如何处理boost :: fileSystem ::路径的空间
- 如果P从root路径开始,为什么STD :: filesystem :: path :: append替换当前路径
- 使用getLastror()== 0的当前路径的负载失败
- 如何在 gcc 中的当前路径下排除标头
- 在 Windows 资源管理器中更改当前路径
- _fullpath返回exes当前路径,而不是驱动器后者
- 更改Qt应用程序的当前路径
- 如何使用Boost.Filesystem更改当前路径?