簡體   English   中英

如何使用Boost.Filesystem更改當前路徑

[英]How can I change the current path using Boost.Filesystem

啟動程序時,我想使用current_path()(“C:\\ workspace \\ projects”)打印當前路徑。 然后我希望能夠改變路徑,讓我們說“c:\\ program files”,所以當我再次打印current_path()時,我想要打印“c:\\ program files”。 像這樣的東西

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

庫中是否有我失蹤的功能,所以我可以實現這個功能?

int main()
{
   cout << current_path() << '\n'; // c:\workspace\projects
   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;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM