Home | History | Annotate | Download | only in string.io
      1 //===----------------------------------------------------------------------===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is dual licensed under the MIT and the University of Illinois Open
      6 // Source Licenses. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 
     10 // <string>
     11 
     12 // template<class charT, class traits, class Allocator>
     13 //   basic_ostream<charT, traits>&
     14 //   operator<<(basic_ostream<charT, traits>& os,
     15 //              const basic_string<charT,traits,Allocator>& str);
     16 
     17 #include <string>
     18 #include <sstream>
     19 #include <cassert>
     20 
     21 #include "min_allocator.h"
     22 
     23 int main()
     24 {
     25     {
     26         std::ostringstream out;
     27         std::string s("some text");
     28         out << s;
     29         assert(out.good());
     30         assert(s == out.str());
     31     }
     32     {
     33         std::ostringstream out;
     34         std::string s("some text");
     35         out.width(12);
     36         out << s;
     37         assert(out.good());
     38         assert("   " + s == out.str());
     39     }
     40     {
     41         std::wostringstream out;
     42         std::wstring s(L"some text");
     43         out << s;
     44         assert(out.good());
     45         assert(s == out.str());
     46     }
     47     {
     48         std::wostringstream out;
     49         std::wstring s(L"some text");
     50         out.width(12);
     51         out << s;
     52         assert(out.good());
     53         assert(L"   " + s == out.str());
     54     }
     55 #if TEST_STD_VER >= 11
     56     {
     57         typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
     58         std::basic_ostringstream<S::value_type, S::traits_type, S::allocator_type> out;
     59         S s("some text");
     60         out << s;
     61         assert(out.good());
     62         assert(s == out.str());
     63     }
     64     {
     65         typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
     66         std::basic_ostringstream<S::value_type, S::traits_type, S::allocator_type> out;
     67         S s("some text");
     68         out.width(12);
     69         out << s;
     70         assert(out.good());
     71         assert("   " + s == out.str());
     72     }
     73     {
     74         typedef std::basic_string<wchar_t, std::char_traits<wchar_t>, min_allocator<wchar_t>> S;
     75         std::basic_ostringstream<S::value_type, S::traits_type, S::allocator_type> out;
     76         S s(L"some text");
     77         out << s;
     78         assert(out.good());
     79         assert(s == out.str());
     80     }
     81     {
     82         typedef std::basic_string<wchar_t, std::char_traits<wchar_t>, min_allocator<wchar_t>> S;
     83         std::basic_ostringstream<S::value_type, S::traits_type, S::allocator_type> out;
     84         S s(L"some text");
     85         out.width(12);
     86         out << s;
     87         assert(out.good());
     88         assert(L"   " + s == out.str());
     89     }
     90 #endif
     91 }
     92