📄 io_matrix.h
字号:
matrix inputmatrix(int m,int n)
{
matrix a(m,n);
double *zh,value=0.0;
zh=new double[M];
int i=0;
int static j=0;
/* Note: The number of "zh" must be equal to
the size of the matrix(columns*rows) */
char sh[20];
cout<<" \nplease input the dir of your matrix "<<(++j)<<" ( matrix.txt )" <<endl;
cin>>sh;
ifstream inClientFile(sh,ios::in);
if(!inClientFile){
cerr<<"File could not be opened!"<<endl;
exit(1);
}
while(inClientFile>>value)
{
zh[i]=value;
i++;
}
a.setdata(zh);
return a;
delete zh;
}
matrix inputmatrix(int m,int n,char sh[])
{
matrix a(m,n);
double *zh,value=0.0;
zh= new double[M];
int i=0;
ifstream inClientFile(sh,ios::in);
if(!inClientFile){
cerr<<"File could not be opened!"<<endl;
exit(1);
}
while(inClientFile>>value)
{
zh[i]=value;
i++;
}
a.setdata(zh);
return a;
delete zh;
}
matrix inputmatrix(int n,char sh[])
{
matrix a(n);
double *zh,value=0.0;
zh=new double[M];
int i=0;
ifstream inClientFile(sh,ios::in);
if(!inClientFile){
cerr<<"File could not be opened!"<<endl;
exit(1);
}
while(inClientFile>>value)
{
zh[i]=value;
i++;
}
a.setdata(zh);
return a;
delete zh;
}
int outputmatrix(matrix a)
{
int i=0,j=0,m=a.getrows(),n=a.getcols();
ofstream outClientFile("output.txt",ios::out);
if(!outClientFile)
{// overloaded ! operator
cerr<<"File could not be opened!"<<endl;
exit(1); //prototype in stdlib.h
}
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
outClientFile<<' '<<a.getele(i,j);
outClientFile<<'\n';
}
return 0;//ofstream destructor closes file
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -