libcxx

libcxx mirror with random patches
git clone https://git.neptards.moe/neptards/libcxx.git
Log | Files | Refs

cp_size_mode.pass.cpp (1228B)


      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 // <strstream>
     11 
     12 // class ostrstream
     13 
     14 // ostrstream(char* s, int n, ios_base::openmode mode = ios_base::out);
     15 
     16 #include <strstream>
     17 #include <cassert>
     18 #include <string>
     19 
     20 int main()
     21 {
     22     {
     23         char buf[] = "123 4.5 dog";
     24         std::ostrstream out(buf, 0);
     25         assert(out.str() == std::string("123 4.5 dog"));
     26         int i = 321;
     27         double d = 5.5;
     28         std::string s("cat");
     29         out << i << ' ' << d << ' ' << s << std::ends;
     30         assert(out.str() == std::string("321 5.5 cat"));
     31     }
     32     {
     33         char buf[23] = "123 4.5 dog";
     34         std::ostrstream out(buf, 11, std::ios::app);
     35         assert(out.str() == std::string("123 4.5 dog"));
     36         int i = 321;
     37         double d = 5.5;
     38         std::string s("cat");
     39         out << i << ' ' << d << ' ' << s << std::ends;
     40         assert(out.str() == std::string("123 4.5 dog321 5.5 cat"));
     41     }
     42 }