You can download this from here or find it in the samples/cpp/tutorial_code/core/file_input_output/file_input_output.cpp of the OpenCV source code library. Here we talk only about XML and YAML file inputs. Your output (and its respective input) file may have only one of these extensions and the structure coming from this. They are two kinds of data structures you may serialize: mappings (like the STL map) and element sequence (like the STL vector). The difference between these is that in a map every element has a unique name through what you may access it. For sequences you need to go through them to query a specific item. Either one of this you use the second argument is a constant specifying the type of operations you’ll be able to on them: WRITE, READ or APPEND. The extension specified in the file name also determinates the output format that will be used. The output may be even compressed if you specify an extension such as .xml.gz. The file automatically closes when the FileStorage objects is destroyed. However, you may explicitly call for this by using the release function: Reading in is a simple addressing (via the  operator) and casting operation or a read via the >,>, operator : For sequence before the first element print the “[” character and after the last one the “]” character: To read from these we use the FileNode and the FileNodeIterator data structures. The  operator of the FileStorage class returns a FileNode data type. If the node is sequential we can use the FileNodeIterator to iterate through the items: It’s possible to serialize this through the OpenCV I/O XML/YAML interface (just as in case of the OpenCV data structures) by adding a read and a write function inside and outside of your class. For the inside part: Here you can observe that in the read section we defined what happens if the user tries to read a non-existing node. In this case we just return the default initialization value, however a more verbose solution would be to return for instance a minus one value for an object ID. Once you added these four functions use the >,>, operator for write and the <,<, operator for read: Source.