ofMatrix4x4 save/load

hi,
ive noticed a couple operator overload functions in ofMatrix4x4

  
  
inline ostream& operator<<(ostream& os, const ofMatrix4x4& M)  
inline istream& operator>>(istream& is, ofMatrix4x4& M)  
  

i assume this for writing ofMatrix4x4 data to a file to be saved and later retrieved.

does anyone have an example of how this is done?

figured it out.

this is to read from file,

  
  
ifstream fileRead;  
fileRead.open("matrix.txt");  
fileRead >> myMatrix;  
fileRead.close();  
  

and this is to write to file,

  
  
ofstream fileWrite;  
fileWrite.open("matrix.txt");  
fileWrite << myMatrix;  
fileWrite.close();  
  

very handy methods!

you can also use ofFile:

  
  
ofFile fileRead("file.txt")  
fileRead >> myMatrix;  
  

  
  
ofFile fileWrite("file.txt",ofFile::WriteOnly)  
fileWrite << myMatrix;  
  

if you do that inside a function the file will be closed automatically after the function ends so no need to call close. that also happens with i/ofstream actually, it’s a c++ pattern called RAII (resource adquisition is initialization): http://en.wikipedia.org/wiki/Resource-Acquisition-Is-Initialization