如何将文件数据存储到3D阵列中 [英] How do I store file data into 3D array
本文介绍了如何将文件数据存储到3D阵列中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我被要求使用3D动力阵列从文件中获取数据,但这给了我任何人帮助的错误
我尝试了什么:
i am asked to get data from a file using a 3D dynamical array but this gives me error can anybody help
What I have tried:
while(FILENAME>>number)
{
if(FILENAME.fail())
{
exit(1);
}
}
int ***Ptr_ptr_ptr=new int **[i];
for(size_t x=0; x<i;> {
Ptr_ptr_ptr[x]=new int *[j];
for(size_t y=0; y<j;> {
Ptr_ptr_ptr[x][y]=new int [k];
}
}
;
for(size_t x=0; x<i;> {
for(size_t y=0; y<j;> {
for(size_t z=0; z<k;> {
FILENAME>>Ptr_ptr_ptr[x][y][z];
}
}
cout<<endl;
}
cout<<"Your values are "<<endl;
for(size_t x=0; x<i;> {
for(size_t y=0; y<j;> {
for(size_t z=0; z<k;> {
cout<<Ptr_ptr_ptr[x][y][z]<<" ";
}
}
cout<<endl;
}
推荐答案
此代码无论如何都无法工作。如果要存储数据,则必须设计文件格式。
为简单起见,我建议使用文本格式,其中每一行都是一个点,x,y和z值用逗号分隔。这就像逗号分隔格式aks cs v文件。可以通过MS Excel或OOCalc打开。
文件的示例数据:
1.1,2.2,3.3(这里有一个新行)
剩下的是简单文件工作和一些循环...
This code wont work anyway. If you want to store data, you must design a file format.
For simplicity I recommand use of text format, in which every line is a point and x,y and z values are separated with a comma. This is knowsn as "comma separated format" aks csv file. It can be opened by MS Excel or OOCalc.
Example data for the file:
1.1,2.2,3.3 (here comes a new line)
The rest is simple file work and some looping...
这篇关于如何将文件数据存储到3D阵列中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文