C++ 如何使用Boost.Filesystem更改当前路径

C++ 如何使用Boost.Filesystem更改当前路径,c++,boost,C++,Boost,启动程序时,我想使用current_path()打印当前路径(“C:\workspace\projects”)。然后我希望能够将路径更改为,比如说“c:\program files”,所以当我再次打印当前路径()时,我希望打印为“c:\program files”。像这样的 int main() { cout << current_path() << endl; // c:\workspace\projects aFunctionToChangePath("

启动程序时,我想使用current_path()打印当前路径(“C:\workspace\projects”)。然后我希望能够将路径更改为,比如说“c:\program files”,所以当我再次打印当前路径()时,我希望打印为“c:\program files”。像这样的

int main()
{
   cout << current_path() << endl;  // c:\workspace\projects
   aFunctionToChangePath("c:\program files");
   cout << current_path() << endl;  // c:\program files
}
intmain()
{
cout
intmain()
{

cout如果您想更改另一个目录,那么我建议您试试这个 例如:

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;
boost::filesystem::path full_path(boost::filesystem::current_path());

std::可以是特定于操作系统的吗?嗯,很简单,我不知道你能做到。非常感谢
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;