I must do a big mistake, but...
Oh, yes, if the second time you want to overwrite the existing data (not just append), use ios::in | ios::out, or simply fstream instead of ofstream. By the way, if you use totu the second time clear is not needed, of course.
What about buying a good book, by the way?!? ;) Such as Josuttis? C++ is a complex language and you cannot hope to learn all of it by trial and error + gcc-help ;)
Paolo.