3 // Copyright (C) 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 2, or (at your option)
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING. If not, write to the Free
18 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
21 // 21.3.7.9 inserters and extractors
23 // NB: This file is predicated on sstreams, istreams, and ostreams
24 // working, not to mention other major details like char_traits, and
25 // all of the string class.
32 #include <testsuite_hooks.h>
36 bool test
__attribute__((unused
)) = true;
37 typedef std::string::size_type csize_type
;
38 typedef std::string::const_reference cref
;
39 typedef std::string::reference ref
;
41 const std::string
str01("sailing grand traverse bay\n"
42 "\t\t\t from Elk Rapids to the point reminds me of miles");
43 const std::string
str02("sailing");
44 const std::string
str03("grand");
45 const std::string
str04("traverse");
46 const std::string str05
;
49 // istream& operator>>(istream&, string&)
50 std::istringstream
istrs01(str01
);
52 VERIFY( str10
== str02
);
55 std::istringstream::int_type i01
= istrs01
.peek(); //a-boo
56 VERIFY( std::istringstream::traits_type::to_char_type(i01
) == ' ' );
58 catch(std::exception
& fail
)
60 VERIFY( false ); // shouldn't throw
65 VERIFY( str10
== str03
);
68 VERIFY( str10
== str04
); // sentry picks out the white spaces. .
70 std::istringstream
istrs02(str05
); // empty
72 VERIFY( str10
== str04
);
74 // istream& getline(istream&, string&, char)
75 // istream& getline(istream&, string&)
79 getline(istrs01
, str10
);
80 VERIFY( !istrs01
.fail() );
81 VERIFY( !istrs01
.eof() );
82 VERIFY( istrs01
.good() );
83 VERIFY( str10
== " bay" );
85 catch(std::exception
& fail
)
87 VERIFY( false ); // shouldn't throw
93 getline(istrs01
, str10
,'\t');
94 VERIFY( !istrs01
.fail() );
95 VERIFY( !istrs01
.eof() );
96 VERIFY( istrs01
.good() );
97 VERIFY( str10
== str05
);
99 catch(std::exception
& fail
)
101 VERIFY( false ); // shouldn't throw
107 getline(istrs01
, str10
,'\t');
108 VERIFY( !istrs01
.fail() );
109 VERIFY( !istrs01
.eof() );
110 VERIFY( istrs01
.good() );
111 VERIFY( str10
== str05
);
113 catch(std::exception
& fail
)
115 VERIFY( false ); // shouldn't throw
121 getline(istrs01
, str10
, '.');
122 VERIFY( !istrs01
.fail() );
123 VERIFY( istrs01
.eof() );
124 VERIFY( !istrs01
.good() );
125 VERIFY( str10
== "\t from Elk Rapids to the point reminds me of miles" );
127 catch(std::exception
& fail
)
129 VERIFY( false ); // shouldn't throw
134 getline(istrs02
, str10
);
135 VERIFY( istrs02
.fail() );
136 VERIFY( istrs02
.eof() );
137 VERIFY( str10
=="\t from Elk Rapids to the point reminds me of miles" );
139 catch(std::exception
& fail
)
141 VERIFY( false ); // shouldn't throw
144 // ostream& operator<<(ostream&, const basic_string&)
145 std::ostringstream ostrs01
;
149 VERIFY( ostrs01
.str() == str01
);
151 catch(std::exception
& fail
)
156 std::string hello_world
;
157 std::cout
<< hello_world
;