Skip to content

Instantly share code, notes, and snippets.

@rayjcwu
Created April 11, 2014 19:04
Show Gist options
  • Save rayjcwu/10492797 to your computer and use it in GitHub Desktop.
Save rayjcwu/10492797 to your computer and use it in GitHub Desktop.
FILE* open (char* filename);
int write(FILE* fd, char* str);
int close(FILE* fd);
class File {
FILE* fd;
public:
File(string filename) {
fd = open(filename.to_c_str());
}
void write(string line) {
int result = write(fd, line.to_c_str());
if (result) {
throw exception;
}
}
~File() {
close(fd);
}
}
void main() {
File f("file.txt");
f.write("test");
// what will happen?
appendLine(f, "line1");
appendLine(f, "line2");
}
void appendLine(File f, string line) {
f.write(line);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment