Home | History | Annotate | Download | only in depr.strstream.cons
      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 strstream
     13 
     14 // strstream(char* s, int n, ios_base::openmode mode = ios_base::in | 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::strstream inout(buf, 0);
     25         assert(inout.str() == std::string("123 4.5 dog"));
     26         int i = 321;
     27         double d = 5.5;
     28         std::string s("cat");
     29         inout >> i;
     30         assert(inout.fail());
     31         inout.clear();
     32         inout << i << ' ' << d << ' ' << s;
     33         assert(inout.str() == std::string("321 5.5 cat"));
     34         i = 0;
     35         d = 0;
     36         s = "";
     37         inout >> i >> d >> s;
     38         assert(i == 321);
     39         assert(d == 5.5);
     40         assert(s == "cat");
     41     }
     42     {
     43         char buf[23] = "123 4.5 dog";
     44         std::strstream inout(buf, 11, std::ios::app);
     45         assert(inout.str() == std::string("123 4.5 dog"));
     46         int i = 0;
     47         double d = 0;
     48         std::string s;
     49         inout >> i >> d >> s;
     50         assert(i == 123);
     51         assert(d == 4.5);
     52         assert(s == "dog");
     53         i = 321;
     54         d = 5.5;
     55         s = "cat";
     56         inout.clear();
     57         inout << i << ' ' << d << ' ' << s;
     58         assert(inout.str() == std::string("123 4.5 dog321 5.5 cat"));
     59     }
     60 }
     61