看板 C_and_CPP 關於我們 聯絡資訊
開發平台(Platform): (Ex: Win10, Linux, ...) Win10 編譯器(Ex: GCC, clang, VC++...)+目標環境(跟開發平台不同的話需列出) Code block 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) 問題(Question):讀檔換行,希望一次讀一行到矩陣中,下一次iteration再讀第二行進 來同樣的矩陣中,進行預算 餵入的資料(Input): 55 148 532 23 72 455 預期的正確結果(Expected Output): 錯誤結果(Wrong Output): 程式碼(Code):(請善用置底文網頁, 記得排版,禁止使用圖檔) for(iteration=0;iterations<2;iteration++) for(i=0;i<3;i++) infile >> a[i] ; .... 補充說明(Supplement): 想請問各位大大,使用infile >> 有什麼指令有辦法直接換行嗎?謝謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 223.136.53.53 ※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1541596839.A.EDB.html
sos0214: 可以用getline + istringstream 11/07 21:45
RobertH: 謝謝樓上,想問有更簡便的方法嗎,因為用infile讀取的話 11/07 23:48
RobertH: ,資料之間需要空一格,還是改用C寫會比較容易? 11/07 23:48
me356500: C的話scanf遇到空格會直接存下一筆 11/07 23:52
me356500: 或是用argv? atoi 11/07 23:52
sos0214: istringstream是可以幫你分割取資料的,詳細google吧 11/08 22:37