[問題] 二維資料讀取,發生錯誤
a.dat 裡面資料是: 1 2 3 4
6 7 8 9
int main()
{
int mat[3][1];
ifstream data_file("a.dat",ios::in);
ofstream out_file("b.dat",ios::out);
int i,j;
for (int i=0;i <= 3;i++){
for (int j=0;j <= 1;j++){
data_file >> mat[i][j];
cout << mat[i][j];
out_file << mat[i][j]; }}
cout <<" mat[0][0] = "<<mat[0][0];
cout <<" mat[1][0] = "<<mat[1][0];
cout <<" mat[2][0] = "<<mat[2][0];
cout <<" mat[3][0] = "<<mat[3][0]<<"\n";
在for裡面cout <<mat[i][j] 顯示正確的12346789
在cout <<mat[0][0] 之後卻顯示 1 3 6 8 ...
我試著放在for迴圈讀也是不正確 不知道為什麼~~~...
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 118.167.9.139
※ 編輯: lyle12345 來自: 118.167.9.139 (05/15 00:23)
推
05/15 01:18, , 1F
05/15 01:18, 1F
→
05/15 01:21, , 2F
05/15 01:21, 2F
→
05/15 01:21, , 3F
05/15 01:21, 3F
推
05/15 01:24, , 4F
05/15 01:24, 4F
→
05/15 01:24, , 5F
05/15 01:24, 5F
→
05/15 01:25, , 6F
05/15 01:25, 6F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章