open_pointer.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_fstream
14
15// void open(const char* s, ios_base::openmode mode = ios_base::in|ios_base::out);
16
17#include <fstream>
18#include <cassert>
19
20int main()
21{
22    {
23        std::fstream fs;
24        assert(!fs.is_open());
25        fs.open("test.dat", std::ios_base::in | std::ios_base::out
26                                              | std::ios_base::trunc);
27        assert(fs.is_open());
28        double x = 0;
29        fs << 3.25;
30        fs.seekg(0);
31        fs >> x;
32        assert(x == 3.25);
33    }
34    std::remove("test.dat");
35    {
36        std::wfstream fs;
37        assert(!fs.is_open());
38        fs.open("test.dat", std::ios_base::in | std::ios_base::out
39                                              | std::ios_base::trunc);
40        assert(fs.is_open());
41        double x = 0;
42        fs << 3.25;
43        fs.seekg(0);
44        fs >> x;
45        assert(x == 3.25);
46    }
47    std::remove("test.dat");
48}
49