En C l'équivalent du record Pascal s'appelle struct.
En
c'est une class. Par exemple une triangulation étant faite
de sommet (vertex) et de triangle, si on s'inspire
du format de fichier pour stocker une triangulation,
on définira la structure suivante:
#include <iostream.h>
#include <fstream.h>
class Vertex { public: float x,y; int where;};
class Triangle { public: int v[3]; int where;};
class Triangulation { public:
int nv,nt;
Vertex* v;
Triangle* t;
Triangulation(const char* path);
};
Triangulation::Triangulation (const char* path)
{// this constructor reads the triangulation from a file
int i,j,k,i1;
ifstream file(path);
file >> nv >> nt;
v = new Vertex[nv];
t = new Triangle[nt];
for( i=0; i<nv; i++)
file >> v[i].x >> v[i].y >> v[i].where;
for( j=0; j<nt; j++)
{ for( k=0; k<3;k++)
{
file >> i1; // fortran convention so i1 starts at 1
t[j].v[k] = --i1; // make it start at 0 (*)
}
file >> t[j].where;
}
file.close();
}