Home | History | Annotate | Download | only in stringbuf.assign
      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 // <sstream>
     11 
     12 // template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
     13 // class basic_stringbuf
     14 
     15 // template <class charT, class traits, class Allocator>
     16 //   void swap(basic_stringbuf<charT, traits, Allocator>& x,
     17 //             basic_stringbuf<charT, traits, Allocator>& y);
     18 
     19 #include <sstream>
     20 #include <cassert>
     21 
     22 int main()
     23 {
     24     {
     25         std::stringbuf buf1("testing");
     26         std::stringbuf buf;
     27         swap(buf, buf1);
     28         assert(buf.str() == "testing");
     29         assert(buf1.str() == "");
     30     }
     31     {
     32         std::stringbuf buf1("testing", std::ios_base::in);
     33         std::stringbuf buf;
     34         swap(buf, buf1);
     35         assert(buf.str() == "testing");
     36         assert(buf1.str() == "");
     37     }
     38     {
     39         std::stringbuf buf1("testing", std::ios_base::out);
     40         std::stringbuf buf;
     41         swap(buf, buf1);
     42         assert(buf.str() == "testing");
     43         assert(buf1.str() == "");
     44     }
     45     {
     46         std::wstringbuf buf1(L"testing");
     47         std::wstringbuf buf;
     48         swap(buf, buf1);
     49         assert(buf.str() == L"testing");
     50         assert(buf1.str() == L"");
     51     }
     52     {
     53         std::wstringbuf buf1(L"testing", std::ios_base::in);
     54         std::wstringbuf buf;
     55         swap(buf, buf1);
     56         assert(buf.str() == L"testing");
     57         assert(buf1.str() == L"");
     58     }
     59     {
     60         std::wstringbuf buf1(L"testing", std::ios_base::out);
     61         std::wstringbuf buf;
     62         swap(buf, buf1);
     63         assert(buf.str() == L"testing");
     64         assert(buf1.str() == L"");
     65     }
     66 }
     67