Skip to content

Instantly share code, notes, and snippets.

@yifu
Created September 18, 2012 15:09
Show Gist options
  • Save yifu/3743654 to your computer and use it in GitHub Desktop.
Save yifu/3743654 to your computer and use it in GitHub Desktop.
#include <fstream>
#include <iostream>
using namespace std;
int main()
{
cout << "Hello world." << std::endl;
ofstream book("test.txt");
cout << "First: " << string(book ? "ok":"non ok") << endl;
cout << "First: " << string(book.is_open() ? "open":"not open") << endl;
// book.open("test.txt");
// cout << "Second: " << string(book ? "ok":"non ok") << endl;
// cout << "Second: " << string(book.is_open() ? "open":"not open") << endl;
book.close();
cout << "Third: " << string(book ? "ok":"non ok") << endl;
cout << "Third: " << string(book.is_open() ? "open":"not open") << endl;
book.open("test.txt");
cout << "Four: " << string(book ? "ok":"non ok") << endl;
cout << "Four: " << string(book.is_open() ? "open":"not open") << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment