2011-04-15 16 views
9

kullanarak nasıl değiştirebilirim Programı başlatırken current_path() ("C: \ workspace \ projects") kullanarak geçerli yolu yazdırmak istiyorum. Ve sonra yolu değiştirebilmek istiyorum, "c: \ program dosyaları" diyelim, böylece tekrar yazdırdığımda current_path() "c: \ program files" basılmak istiyorum. BuGeçerli yolu Boost.Filesystem

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

gibi bir şey ben bu Tamamladılar böylece eksik kütüphanede bir işlevi var mı?

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; 
+0

zaman os özgü izin mi: – RedX

+0

evet, onun da onun gibi – Kobe

cevap

13
int main() 
{ 
    cout << current_path() << '\n'; // c:\workspace\projects 
    current_path("c:\\program files"); 
    cout << current_path() << '\n'; // c:\program files 
} 
+0

Hmm, bu basit, bunu yapabileceğini bilmiyordum. Teşekkürler – Kobe

1

farklı bir dizine bir değişiklik yapmak istiyorsanız

, o zaman bu örnek denemenizi öneririz?
+0

Bu bağlantı soruyu yanıtlayabilirken, cevabın temel kısımlarını buraya dahil etmek ve referans için bağlantı sağlamak daha iyidir. Bağlantılı sayfa değiştiğinde yalnızca bağlantı yanıtları geçersiz olabilir. – Jeroen

+0

Katılıyorum - bu yüzden onu düzelttim – serup

İlgili konular