open_string.pass.cpp revision f5256e16dfc425c1d466f6308d4026d529ce9e0b
1//===----------------------------------------------------------------------===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10// <fstream>
11
12// template <class charT, class traits = char_traits<charT> >
13// class basic_ofstream
14
15// void open(const string& s, ios_base::openmode mode = ios_base::out);
16
17#include <fstream>
18#include <cassert>
19
20int main()
21{
22    {
23        std::ofstream fs;
24        assert(!fs.is_open());
25        char c = 'a';
26        fs << c;
27        assert(fs.fail());
28        fs.open(std::string("test.dat"));
29        assert(fs.is_open());
30        fs << c;
31    }
32    {
33        std::ifstream fs("test.dat");
34        char c = 0;
35        fs >> c;
36        assert(c == 'a');
37    }
38    remove("test.dat");
39    {
40        std::wofstream fs;
41        assert(!fs.is_open());
42        wchar_t c = L'a';
43        fs << c;
44        assert(fs.fail());
45        fs.open(std::string("test.dat"));
46        assert(fs.is_open());
47        fs << c;
48    }
49    {
50        std::wifstream fs("test.dat");
51        wchar_t c = 0;
52        fs >> c;
53        assert(c == L'a');
54    }
55    remove("test.dat");
56}
57