How to use ofBuffer to append to a file

Hello,

I’m trying to save a few values to xml (via ofxXmlSettings).
I’d like to leave an oF app running and while it does, append values to an xml node.

I’ve got something like this:

  
  
//called once on setup()  
trackFile.open(ofToDataPath("stream.xml"), ofFile::Append, false);  
  
//called multiple times on update()  
string trackStr = ofToString(trackXML);  
//trackBuffer.set(const char *_buffer, <#int _size#>) //how do I plug the xml to the buffer  
trackFile.writeFromBuffer(trackBuffer);  
  
//called once on event  
trackFile.close();  
  

Unfortunately I’m not experienced with File I/O in c++/oF
so any hints/tips would help.

Thanks,
George

If your using ofxXmlSettings you don’t need to manually write to an ofFile, you just set the values. Have you seen the xmlSettingsExample in the addonsExamples folder?

But, if you are wanting to manually write to an ofFile, you can try something like this…

file.open(“yourfile.xml”, ofFile::WriteOnly);
file << “10” + “\n”;
file.close;

That’s pretty cool! I need to learn by basics (File I/O) :slight_smile:
Thank you for this