精華區beta C_and_CPP 關於我們 聯絡資訊
開發平台(Platform): (Ex: Win10, Linux, ...) win10 編譯器(Ex: GCC, clang, VC++...)+目標環境(跟開發平台不同的話需列出) viusal studio 內的c# 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) 問題(Question): 換檔案讀取後就無法正常運作 餵入的資料(Input): 1.txt內容 1234567where is my friend? sorry 你沒朋友 2.txt內容 7654321where do you live sorry i cannot tell you 預期的正確結果(Expected Output): 1.txt 1234567where is my friend 2.txt 7654321where do you live 錯誤結果(Wrong Output): 1.txt結果是成功的 2.txt結果 7654321 i tell you 程式碼(Code):(請善用置底文網頁, 記得排版,禁止使用圖檔) using (StreamReader sr = new StreamReader(@"C:\Users\Administrator\Desktop.1.t xt")) while (sr.Peek() != -1) { string line = sr.ReadLine(); foreach (var ch in line) { string[] words = line.Split(); string together = string.Join(" ", words); string x = sr.ReadLine(); if (x == "sorry") { break; } Console.WriteLine(x); } } Console.Read(); 補充說明(Supplement): 想請問版上的高手們應該如何修改呢? -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 42.74.47.23 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1564661452.A.D84.html
sarafciel: 我建議你先看一下版標XD08/01 20:13
啊啊啊剛剛太急了沒有發現,感謝您的提醒 ※ 編輯: follow4ab (42.74.47.23 臺灣), 08/01/2019 20:27:15