Created
February 8, 2009 05:35
-
-
Save scooby/60217 to your computer and use it in GitHub Desktop.
tests ios modes when file doesn't exist; which ones will create file
This file contains hidden or 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
#include <fstream> | |
#include <iostream> | |
using namespace std; | |
void test(ios_base::openmode bits, char* name) { | |
fstream f; | |
f.open(name, bits); | |
cout << "Tried " << name; | |
if(f.is_open()) { | |
cout << " and was successful." << endl; | |
f.close(); | |
} else { | |
cout << " and failed." << endl; | |
} | |
} | |
int main(void) { | |
ios_base::openmode m = ios_base::out; | |
test(m, "out"); | |
test(m | ios_base::trunc, "out trunc"); | |
test(m | ios_base::app, "out app"); | |
test(m | ios_base::ate, "out ate"); | |
m = ios_base::in; | |
test(m, "in"); | |
test(m | ios_base::trunc, "in trunc"); | |
test(m | ios_base::app, "in app"); | |
test(m | ios_base::ate, "in ate"); | |
m = ios_base::in | ios_base::out; | |
test(m, "inout"); | |
test(m | ios_base::trunc, "inout trunc"); | |
test(m | ios_base::app, "inout app"); | |
test(m | ios_base::ate, "inout ate"); | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment