Designing a class to do simple file I/O using streams.

I'm having trouble with this. I'm not even sure where to start. What goes in the Class .cpp and what goes in the Class .h file? Thanks in advance.

Design and define a class called FileIO to do simple file I/O using streams. You can add other attributes and/or methods other than what is defined below, if you deem them necessary.
1. Class FileIO should contain the following as a minimum:
a. A default constructor and destructor.
b. An overloaded constructor, with default values for each argument.
c. Setters and getters for public-facing attributes.
d. Other methods:
d1. bool open(string filename, string mode) // mode = "read" or "write"
d2. void close()
d3. void write(string data)
e. Attributes:
e1. File name - a string for the file name
e2. Open mode - something that indicates how the file is to be opened - read or write
e3. An fstream
2. In main:
a. Use the FileIO class to open a file for writing and write 3 lines of data to it.
Submit a zip file of your visual studio project.
Does your professor not realize that C++ provides classes for exactly this?
I'm sure he does.
Then your class is simply going to be a wrapper around the STL classes designed for doing this. What's your question exactly?
a. A default constructor and destructor.
b. An overloaded constructor, with default values for each argument.


If you provided default values for each argument, wouldn't that create an ambiguity with the default constructor?
Last edited on
If you provided default values for each argument, wouldn't that create an ambiguity with the default constructor?

That's an interesting question. I'm not at home or else I'd test this. Hopefully someone pops in here who knows the answer to this.
Topic archived. No new replies allowed.