1
我创建了一个FILE.DAT蒙山此功能C++矩阵数据保存到文本或XML(更好)
int writeData(double* v, int length, FILE* fh)
{
FILE *Stream; //Stream for output.
double*Elem; //Pointer to all the element to save.
assert(fh!=NULL);
Stream = fh;
Elem=(double*)malloc((length+2)*sizeof(double));//Allocate memory to Elem.
if(Elem==NULL)
{
printf("Can't allocate memory for saving the matrix!");
return(0);
}
Elem[0]=(double)1;//Save the dimensions of the matrix.
Elem[1]=(double)length;
int i;
for(i=0;i<length ;i++)
Elem[i+2]=v[i];
if(fwrite((void*)Elem,sizeof(double),(length+2),Stream) < (unsigned)(length+2)) //Save the data.
{
printf("Error, can't save the matrix!");
return(0);
}
free(Elem);
return(1);
}
现在我想把这个文件转换为XML的一个或到一个文本文件.. 。
任何提示? 感谢
所以你实际上是想要保存矩阵表示的XML或文本格式?这就是问题标题应该提到的。我实际上编辑过它。希望这就是你的意思。 – EFraim 2010-12-08 21:31:26