-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.cpp
66 lines (54 loc) · 1.11 KB
/
test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <fstream>
using namespace std;
struct point {
float x;
float y;
float z;
};
typedef point triangle[3];
triangle** data;
int data_count = -1;
void display(void);
/*----------
file_in(): file input function. Modify here.
------------*/
void file_in(void)
{
char* filePath = "sphere.8";
ifstream file(filePath);
if(file.fail()){
cout <<"Cannot open file "<<filePath<<endl;
exit(0);
}
file >> data_count;
cout <<"Total number of record: "<<data_count<<endl;
//dynamic memory arrangement
data = new triangle*[data_count];
int index = 0;
while(!file.eof()){
int v_num;
file >> v_num;
//为什么这个tri变量在每次循环中地址都是一样的?
triangle tri;
for(int i=0; i<v_num; i++){
file >> tri[i].x >> tri[i].y >> tri[i].z;
}
data[index] = &tri;
index++;
}
}
void main(int argc, char **argv)
{
file_in();
display();
}
void display(void)
{
for(int i=0;i<data_count;i++){
triangle* p = data[i];
cout << (*p)[0].x <<" "<<(*p)[0].y <<" "<<(*p)[0].z<< endl;
}
}