[問題] 讀檔問題
( *[1m *[m 為色碼,可以按 Ctrl+V 預覽會顯示的顏色 )
( 未必需要依照此格式,文章條理清楚即可 )
遇到的問題: (題意請描述清楚)
1 5 紅處是多一空格
8 -9
為何程式就會亂跑
如果把空格去掉(就是在5後面不要多按一space)
就正確
願聞其詳
謝
有問題的code: (請善用置底文標色功能)
#include <iostream>
#include <iomanip>
using namespace std;
#include <string>
#include <fstream>
#include <cstdlib>
int main()
{
string filename;
int deter_row, deter_column, numA[10][10];
char check;
int sum=0,row=0,column=0,k;
ifstream read;
cin>>filename;
read.open(filename.c_str());
if (read.fail()) // check for a successful open
{
cout << "\nThe file was not successfully opened"
<< "\n Please check that the file currently exists." <<endl;
system("pause");
exit(0);
}
cout << "\nThe file has been successfully opened for reading"<< endl;
do
{
read>>numA[row][column];
column=column+1;
if((check=read.get())=='\n')
{
row=row+1;
column=0;
}
}while(read.good());
for(int ii=0;ii<=row;ii++)
{
for(int jj=0;jj<column;jj++)
{
cout<<setw(3)<<numA[ii][jj];
}
cout<<endl;
}
deter_row=row+1;
deter_column=column;
system("pause");
return 0;
}
編譯過的
補充說明:
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.112.7.59
推
12/28 09:51, , 1F
12/28 09:51, 1F
→
12/28 09:52, , 2F
12/28 09:52, 2F
→
12/28 09:52, , 3F
12/28 09:52, 3F
討論串 (同標題文章)