Hi everyone, I'm not a C++ guru and so would need a little help please !
For 3D matters, I created a class vertex3D:
class vertex3D
{
public:
float verX; // x coordinate
float verY; // huh
float verZ;
...
As I save the coordinates in a file, I added the operator << to my class:
ostream & operator << (ostream &o, const vertex3D &v)
{
return o << v.verX << " " << v.verY << " " << v.verZ << endl;
}
and use the following code in the main function:
vertex3D vertex_Array[nb_vertices];
...
ofstream recordfile;
for (i=0; i< nb_vertices; i++) recordfile << vertex_Array;
recordfile.close();
All this works well, but now I'd like to read the coordinates from the file via the >> operator, and this is where I'm stuck (told you I'm not a guru !).
I tried to add the function:
friend ifstream & operator >> (ifstream &, vertex3D &);
istream & operator >> (istream &i, vertex3D &v)
{
return i >> v.verX >> v.verY >> v.verZ;
}
VC++ compiles the code without indicating any error, but if I try:
for (int i=0; i< nb_vertices; i++) I >> vertex_Array; // read the coordinates from file
I get:
Linking...
main.obj : error LNK2001: unresolved external symbol "class ifstream & __cdecl operator>>(class ifstream &,class vertex3D &)" (??5@YAAAVifstream@@AAV0@AAVvertex3D@@@Z)
Debug/Tree.exe : fatal error LNK1120: 1 unresolved externals
The former code I used in the main function worked well:
for (int i=0; i< nb_vertices; i++)
I >> vertex_Array.verX >> vertex_Array.verY >> vertex_Array.verZ;
Anyone can help me please ???
For 3D matters, I created a class vertex3D:
class vertex3D
{
public:
float verX; // x coordinate
float verY; // huh
float verZ;
...
As I save the coordinates in a file, I added the operator << to my class:
ostream & operator << (ostream &o, const vertex3D &v)
{
return o << v.verX << " " << v.verY << " " << v.verZ << endl;
}
and use the following code in the main function:
vertex3D vertex_Array[nb_vertices];
...
ofstream recordfile;
for (i=0; i< nb_vertices; i++) recordfile << vertex_Array;
recordfile.close();
All this works well, but now I'd like to read the coordinates from the file via the >> operator, and this is where I'm stuck (told you I'm not a guru !).
I tried to add the function:
friend ifstream & operator >> (ifstream &, vertex3D &);
istream & operator >> (istream &i, vertex3D &v)
{
return i >> v.verX >> v.verY >> v.verZ;
}
VC++ compiles the code without indicating any error, but if I try:
for (int i=0; i< nb_vertices; i++) I >> vertex_Array; // read the coordinates from file
I get:
Linking...
main.obj : error LNK2001: unresolved external symbol "class ifstream & __cdecl operator>>(class ifstream &,class vertex3D &)" (??5@YAAAVifstream@@AAV0@AAVvertex3D@@@Z)
Debug/Tree.exe : fatal error LNK1120: 1 unresolved externals
The former code I used in the main function worked well:
for (int i=0; i< nb_vertices; i++)
I >> vertex_Array.verX >> vertex_Array.verY >> vertex_Array.verZ;
Anyone can help me please ???