Created
April 11, 2014 19:04
-
-
Save rayjcwu/10492797 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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