[問題] txt檔案讀取一行,放入到陣列並顯示
開發平台(Platform): (Ex: Win10, Linux, ...)
Windows 10
編譯器(Ex: GCC, clang, VC++...)+目標環境(跟開發平台不同的話需列出)
vs2019
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
問題(Question):
要把一個文字檔案,程式讀取每一行之後,透過寫入到陣列
然後呈現
餵入的資料(Input):
這是我的顯示,右邊是我設定的每一行的陣列
https://imgur.com/mPT1Bcc



這邊我只有先測試讀取到data_array[0][0]~data_array[2][3]的內容
程式碼(Code):(請善用置底文網頁, 記得排版,禁止使用圖檔)
Sleep(5000);
//5秒開始,目前回傳以密碼原則12條為主:檢查全部內容
string data_array[5][4];
ifstream Read_PwdRevisTxt; //要讀取的修改檔-PwdRevis
Read_PwdRevisTxt.open("computer01.txt");
for(int i=0;i<5;i++)
{
for (int j = 0; j < 4; j++)
{
Read_PwdRevisTxt >> data_array[i][j];
}
}
Read_PwdRevisTxt.close(); //讀取完畢要關閉
cout << data_array[0][0] << endl;
cout << data_array[0][1] << endl;
cout << data_array[0][2] << endl;
cout << data_array[0][3] << endl;
cout << data_array[1][0] << endl;
cout << data_array[1][1] << endl;
cout << data_array[1][2] << endl;
cout << data_array[1][3] << endl;
cout << data_array[2][0] << endl;
cout << data_array[2][1] << endl;
cout << data_array[2][2] << endl;
cout << data_array[2][3] << endl;
補充說明(Supplement):
我找到的問題,他好像只要有空白、tab,就會直接寫入陣列內@@
我要的是一行對應一個array這樣
有大大可以告訴我怎麼解決這問題嗎?
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 218.161.102.123 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1568287041.A.636.html
※ 編輯: jayzhuang (218.161.102.123 臺灣), 09/12/2019 19:18:03
→
09/12 19:57,
6年前
, 1F
09/12 19:57, 1F
推
09/12 21:14,
6年前
, 2F
09/12 21:14, 2F
→
09/12 21:14,
6年前
, 3F
09/12 21:14, 3F
推
09/12 22:55,
6年前
, 4F
09/12 22:55, 4F
謝謝各位大大,我再改看看
依照g大的方式,是可行!
不過他連換行也加入到array裡面了@@.....
※ 編輯: jayzhuang (218.161.102.123 臺灣), 09/16/2019 10:50:38
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 1 之 2 篇):
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章