brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.1 KiB · ca0921a Raw
76 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_fstream13 14// explicit basic_fstream(const string& s, ios_base::openmode mode = ios_base::in|ios_base::out);15 16#include <fstream>17#include <cassert>18 19#include "test_macros.h"20#include "platform_support.h"21#include "operator_hijacker.h"22 23int main(int, char**)24{25    std::string temp = get_temp_file_name();26    {27        std::fstream fs(temp,28                        std::ios_base::in | std::ios_base::out29                                          | std::ios_base::trunc);30        double x = 0;31        fs << 3.25;32        fs.seekg(0);33        fs >> x;34        assert(x == 3.25);35    }36    std::remove(temp.c_str());37 38    {39      std::basic_fstream<char, operator_hijacker_char_traits<char> > fs(40          temp, std::ios_base::in | std::ios_base::out | std::ios_base::trunc);41      std::basic_string<char, operator_hijacker_char_traits<char> > x;42      fs << "3.25";43      fs.seekg(0);44      fs >> x;45      assert(x == "3.25");46    }47    std::remove(temp.c_str());48 49#ifndef TEST_HAS_NO_WIDE_CHARACTERS50    {51        std::wfstream fs(temp,52                         std::ios_base::in | std::ios_base::out53                                           | std::ios_base::trunc);54        double x = 0;55        fs << 3.25;56        fs.seekg(0);57        fs >> x;58        assert(x == 3.25);59    }60    std::remove(temp.c_str());61 62    {63      std::basic_fstream<wchar_t, operator_hijacker_char_traits<wchar_t> > fs(64          temp, std::ios_base::in | std::ios_base::out | std::ios_base::trunc);65      std::basic_string<wchar_t, operator_hijacker_char_traits<wchar_t> > x;66      fs << L"3.25";67      fs.seekg(0);68      fs >> x;69      assert(x == L"3.25");70    }71    std::remove(temp.c_str());72#endif73 74  return 0;75}76