Please edit your post and make sure your code is [code]between code tags[/code] so that it has line numbers and syntax highlighting, as well as proper indentation.
The tutorial on this site, although somewhat dated, should be helpful: http://www.cplusplus.com/doc/tutorial/files/
Just note that there is almost no reason to ever use .open() or .close()