blob: 1ad0bfa8e2695eecfdb3a162a94e8e09e9d186c7 [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 ostrstream
13
14// ostrstream(char* s, int n, ios_base::openmode mode = ios_base::out);
15
16#include <strstream>
17#include <cassert>
18
19int main()
20{
21 {
22 char buf[] = "123 4.5 dog";
23 std::ostrstream out(buf, 0);
24 assert(out.str() == std::string("123 4.5 dog"));
25 int i = 321;
26 double d = 5.5;
27 std::string s("cat");
Howard Hinnantcaee2b02012-06-01 20:02:59 +000028 out << i << ' ' << d << ' ' << s << std::ends;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000029 assert(out.str() == std::string("321 5.5 cat"));
30 }
31 {
32 char buf[23] = "123 4.5 dog";
33 std::ostrstream out(buf, 11, std::ios::app);
34 assert(out.str() == std::string("123 4.5 dog"));
35 int i = 321;
36 double d = 5.5;
37 std::string s("cat");
Howard Hinnantcaee2b02012-06-01 20:02:59 +000038 out << i << ' ' << d << ' ' << s << std::ends;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000039 assert(out.str() == std::string("123 4.5 dog321 5.5 cat"));
40 }
41}