Take a look at the relevant section of the tutorial on this site, it covers the basics nicely, and shoudl put you in a position to either do what you want, or ask much more targeted questiosn if not.
Link: http://www.cplusplus.com/doc/tutorial/files.html