brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.6 KiB · 33a7e9b Raw
127 lines · cpp
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9// <fstream>10 11// template <class charT, class traits = char_traits<charT> >12// class basic_ofstream13 14// explicit basic_ofstream(const string& s, ios_base::openmode mode = ios_base::out);15 16#include <fstream>17#include <cassert>18#include <ios>19 20#include "test_macros.h"21#include "operator_hijacker.h"22#include "platform_support.h"23 24int main(int, char**)25{26    std::string temp = get_temp_file_name();27 28    {29        std::ofstream fs(temp);30        fs << 3.25;31    }32    {33        std::ifstream fs(temp);34        double x = 0;35        fs >> x;36        assert(x == 3.25);37    }38    std::remove(temp.c_str());39 40    {41      std::basic_ofstream<char, operator_hijacker_char_traits<char> > fs(temp);42      fs << "3.25";43    }44    {45      std::ifstream fs(temp);46      double x = 0;47      fs >> x;48      assert(x == 3.25);49    }50    std::remove(temp.c_str());51 52    {53      std::ofstream fs(temp, std::ios_base::out);54      fs << 3.25;55    }56    {57      std::ifstream fs(temp);58      double x = 0;59      fs >> x;60      assert(x == 3.25);61    }62    std::remove(temp.c_str());63 64    {65      std::basic_ofstream<char, operator_hijacker_char_traits<char> > fs(temp, std::ios_base::out);66      fs << "3.25";67    }68    {69      std::ifstream fs(temp);70      double x = 0;71      fs >> x;72      assert(x == 3.25);73    }74    std::remove(temp.c_str());75#ifndef TEST_HAS_NO_WIDE_CHARACTERS76    {77        std::wofstream fs(temp);78        fs << 3.25;79    }80    {81        std::wifstream fs(temp);82        double x = 0;83        fs >> x;84        assert(x == 3.25);85    }86    std::remove(temp.c_str());87 88    {89      std::basic_ofstream<wchar_t, operator_hijacker_char_traits<wchar_t> > fs(temp);90      fs << L"3.25";91    }92    {93      std::wifstream fs(temp);94      double x = 0;95      fs >> x;96      assert(x == 3.25);97    }98    std::remove(temp.c_str());99 100    {101      std::wofstream fs(temp, std::ios_base::out);102      fs << 3.25;103    }104    {105      std::wifstream fs(temp);106      double x = 0;107      fs >> x;108      assert(x == 3.25);109    }110    std::remove(temp.c_str());111 112    {113      std::basic_ofstream<wchar_t, operator_hijacker_char_traits<wchar_t> > fs(temp, std::ios_base::out);114      fs << L"3.25";115    }116    {117      std::wifstream fs(temp);118      double x = 0;119      fs >> x;120      assert(x == 3.25);121    }122    std::remove(temp.c_str());123#endif124 125  return 0;126}127