io_matrix.h
来自「用 c++编写的GPS水准拟合的程序」· C头文件 代码 · 共 86 行
H
86 行
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 + =
减小字号Ctrl + -
显示快捷键?