Re: [問題] BCB DirectoryListBox
※ 引述《honoYang (翻譯姬)》之銘言:
: 各位大大好
: 看到現在這個時間
: 就知道我快被這個問題搞瘋了
: BCB底下有個DirectoryListBox可以點選其所列的資料夾
: 當我還沒按它時
: 假如我要input某個檔案例如如下
: std::ifstream infile("BCB\\abc.txt")
: 是沒有問題的
: 但是當我按下了DirectoryListBox選某個資料夾後
: 再去做讀檔
: std::ifstream infile("BCB\\abc.txt")
: 就會發現找不到這個檔,但它其實是存在的
: 前後只差了有去選取DirectoryListBox其中的資料夾
: 我都還沒做出任何動作
: 檔案已經不能讀取了
: (選取DirectoryListBox其中的資料夾就只是雙擊它而已
: 不會有任何動作)
: 經反覆測試後發現
: 如果是讀取和EXE及project目錄下的檔案就可以
: 例如直接
: std::ifstream infile("def.txt")
: 但如果要讀取其他資料夾下的檔案就不能
: 即使設了絕對路徑也一樣
: 我想了很久
: 在天亮前
: 還是想說來問問看好了
: 拜託大家了
自問自答一下
如果我有個叫BCB的資料夾
BCB資料夾裡有個abc.txt
std::string a=ExtractFilePath(DirectoryListBox1->Directory).c_str();
std::string b=ExtractFilePath(Application->ExeName).c_str();
std::ifstream infile((a+"BCB\\Male.txt").c_str());
這樣是可以的
但如果變成以下
std::string a=(DirectoryListBox1->Directory).c_str();
std::string b=ExtractFilePath(Application->ExeName).c_str();
std::ifstream infile((a+"BCB\\Male.txt").c_str());
就讀不到檔案
如果稍微修改成這樣
std::string a=(DirectoryListBox1->Directory).c_str();
std::string b=ExtractFilePath(Application->ExeName).c_str();
std::ifstream infile((a+"\\BCB\\Male.txt").c_str());
就OK
原因在於
ExtractFilePath會自動在字串後加上"\\"
而DirectoryListBox1->Directory不會
--
"帥哥~~~來喔!!"
"\⊙▽⊙/ 來啊來啊"
"帥哥~~~抹呷啥???
"(  ̄ c ̄)y▂ξ 老闆娘 妳只想要我的錢
而不是我的身體"
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.112.94.123
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章