看板 C_and_CPP 關於我們 聯絡資訊
*[36m開發平台(Platform): Win 10 編譯器(Ex: GCC, clang, VC++...)+目標環境(跟開發平台不同的話需列出) VC++ 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) 問題(Question): 如何將txt檔內的矩陣資料讀取出來,因為txt檔內的資 料不只有數字,還有其他英文夾雜,而檔案內有兩筆矩陣資料,需要分別儲存,之後 要做運算。 餵入的資料(Input): txt檔內容: Matrix_Multiplication Name : A1 1 2 3 ; 4 5 6 ; 7 5 9 ; Name : B1 2 2 3 ; 4 5 5 ; 8 8 7 ; End_Matrix_Multiplication 預期的正確結果(Expected Output): 錯誤結果(Wrong Output): 程式碼(Code):(請善用置底文網頁, 記得排版) 補充說明(Supplement): 我的想法是用getline()去做,遇到A1則下面 的數字開始做儲存,同理,遇到B2也是一樣。但從一開始就不知如何讀取矩陣, 希望版上高手可以指導一下小弟這個初學者。(用C++寫的) -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 114.32.254.27 ※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1476858287.A.26A.html ※ 編輯: ouynln (114.34.29.120), 10/19/2016 14:28:37
suwako: 你有預期的程式架構嗎? 10/19 14:31
stupid0319: 不要想成矩陣就好了,一行一行處理 10/19 14:33
不好意思,不太懂您的意思,可以請您再說詳細一點嗎,非常謝謝! ※ 編輯: ouynln (114.32.254.27), 10/19/2016 14:49:27
godspeedlee: 你是要把矩陣資料轉成 C/C++ array? 10/19 14:51
是的!! ※ 編輯: ouynln (114.32.254.27), 10/19/2016 14:54:01
godspeedlee: 全部讀到std::vector<std::string>再處理不是比較 10/19 15:07
godspeedlee: 簡單嗎? 10/19 15:07
pttworld: 怎麼寫通常是資結有了就容易。struct, class先定。 10/19 16:19
suwako: 你要先說你打算怎麼做 我們才有辦法跟你講code怎麼寫阿 10/19 17:19
suwako: 你的矩陣有固定的大小嗎 一律3x3? 10/19 17:20
是不固定的 ※ 編輯: ouynln (140.135.9.165), 10/19/2016 21:05:04
pttworld: 資料沒有規律也不需寫讀檔程式了,寫literal處理。 10/19 22:46
pttworld: 也可以挖當初寫檔程式參考。 10/19 22:46