[問題] C++的字串路徑

看板C_and_CPP (C/C++)作者 ( )時間12年前 (2014/02/26 19:58), 編輯推噓0(004)
留言4則, 3人參與, 最新討論串1/1
開發平台(Platform): (Ex: VC++, GCC, Linux, ...) Linux, vim, gcc 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) cstring, iostream, fstream 問題(Question): argv[2]是user會輸入的檔名 讀的檔案放在 HW1/inputs/ main.cpp放在 HW1/src/main.cpp 餵入的資料(Input): argv[2]是user會輸入的檔名 預期的正確結果(Expected Output): 希望能將user輸入的檔名讀進來 錯誤結果(Wrong Output): compile不會過 相關訊息如下: warning: missing terminating " character error: missing terminating " character initializer fails to determine size of ‘filePath’ 程式碼(Code):(請善用置底文網頁, 記得排版) http://ideone.com/pineDc 補充說明(Supplement): code是我自己寫的 看錯誤訊息應該是我字串處理不當 請高手給予指點 謝謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.118.150.2 ※ 編輯: wsx100 來自: 140.118.150.2 (02/26 20:01)

02/26 20:02, , 1F
\ 要改成 \\
02/26 20:02, 1F

02/26 20:02, , 2F
然後你filePath沒有給足夠的空間,strcat會爆炸
02/26 20:02, 2F

02/26 20:03, , 3F
".\\inputs\" => "./inputs/" or ".\\inputs\\"
02/26 20:03, 3F
感謝兩位的幫忙 compile過了 可是檔案還沒有成功讀入 假設user給的檔名是 test.txt 我的filePath = ./inputs/test.txt 用這個路徑去open是失敗的? 想再請問是不是這樣的路徑還是錯的呢? 執行檔在 HW1/result/ test.txt在 HW1/inputs/ 謝謝 ※ 編輯: wsx100 來自: 140.118.150.2 (02/26 20:22)

02/26 21:12, , 4F
"."代表的是目前的資料夾…你的狀況要用../inputs/test
02/26 21:12, 4F
文章代碼(AID): #1J3TRdU8 (C_and_CPP)
文章代碼(AID): #1J3TRdU8 (C_and_CPP)