Added a writing out funciton to example.cpp