blob: 2a4c0ec5aa201a08748b1d22accd1b3ad34e1cc5 [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001//===----------------------------------------------------------------------===//
2//
Howard Hinnantf5256e12010-05-11 21:36:01 +00003// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00005// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00007//
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>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000018
19int main()
20{
21 {
22 char buf[] = "123 4.5 dog";
23 std::strstream inout(buf, 0);
24 assert(inout.str() == std::string("123 4.5 dog"));
25 int i = 321;
26 double d = 5.5;
27 std::string s("cat");
28 inout >> i;
29 assert(inout.fail());
30 inout.clear();
31 inout << i << ' ' << d << ' ' << s;
32 assert(inout.str() == std::string("321 5.5 cat"));
33 i = 0;
34 d = 0;
35 s = "";
36 inout >> i >> d >> s;
37 assert(i == 321);
38 assert(d == 5.5);
39 assert(s == "cat");
40 }
41 {
42 char buf[23] = "123 4.5 dog";
43 std::strstream inout(buf, 11, std::ios::app);
44 assert(inout.str() == std::string("123 4.5 dog"));
45 int i = 0;
46 double d = 0;
47 std::string s;
48 inout >> i >> d >> s;
49 assert(i == 123);
50 assert(d == 4.5);
51 assert(s == "dog");
52 i = 321;
53 d = 5.5;
54 s = "cat";
55 inout.clear();
56 inout << i << ' ' << d << ' ' << s;
57 assert(inout.str() == std::string("123 4.5 dog321 5.5 cat"));
58 }
59}