]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/21_strings/basic_string/inserters_extractors/char/1.cc
3 // Copyright (C) 1999-2016 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 3, 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 COPYING3. If not see
18 // <http://www.gnu.org/licenses/>.
20 // 21.3.7.9 inserters and extractors
22 // NB: This file is predicated on sstreams, istreams, and ostreams
23 // working, not to mention other major details like char_traits, and
24 // all of the string class.
31 #include <testsuite_hooks.h>
35 bool test
__attribute__((unused
)) = true;
36 typedef std::string::size_type csize_type
;
37 typedef std::string::const_reference cref
;
38 typedef std::string::reference ref
;
40 const std::string
str01("sailing grand traverse bay\n"
41 "\t\t\t from Elk Rapids to the point reminds me of miles");
42 const std::string
str02("sailing");
43 const std::string
str03("grand");
44 const std::string
str04("traverse");
45 const std::string str05
;
48 // istream& operator>>(istream&, string&)
49 std::istringstream
istrs01(str01
);
51 VERIFY( str10
== str02
);
54 std::istringstream::int_type i01
= istrs01
.peek(); //a-boo
55 VERIFY( std::istringstream::traits_type::to_char_type(i01
) == ' ' );
57 catch(std::exception
& fail
)
59 VERIFY( false ); // shouldn't throw
64 VERIFY( str10
== str03
);
67 VERIFY( str10
== str04
); // sentry picks out the white spaces. .
69 std::istringstream
istrs02(str05
); // empty
71 VERIFY( str10
== str04
);
73 // istream& getline(istream&, string&, char)
74 // istream& getline(istream&, string&)
78 getline(istrs01
, str10
);
79 VERIFY( !istrs01
.fail() );
80 VERIFY( !istrs01
.eof() );
81 VERIFY( istrs01
.good() );
82 VERIFY( str10
== " bay" );
84 catch(std::exception
& fail
)
86 VERIFY( false ); // shouldn't throw
92 getline(istrs01
, str10
,'\t');
93 VERIFY( !istrs01
.fail() );
94 VERIFY( !istrs01
.eof() );
95 VERIFY( istrs01
.good() );
96 VERIFY( str10
== str05
);
98 catch(std::exception
& fail
)
100 VERIFY( false ); // shouldn't throw
106 getline(istrs01
, str10
,'\t');
107 VERIFY( !istrs01
.fail() );
108 VERIFY( !istrs01
.eof() );
109 VERIFY( istrs01
.good() );
110 VERIFY( str10
== str05
);
112 catch(std::exception
& fail
)
114 VERIFY( false ); // shouldn't throw
120 getline(istrs01
, str10
, '.');
121 VERIFY( !istrs01
.fail() );
122 VERIFY( istrs01
.eof() );
123 VERIFY( !istrs01
.good() );
124 VERIFY( str10
== "\t from Elk Rapids to the point reminds me of miles" );
126 catch(std::exception
& fail
)
128 VERIFY( false ); // shouldn't throw
133 getline(istrs02
, str10
);
134 VERIFY( istrs02
.fail() );
135 VERIFY( istrs02
.eof() );
136 VERIFY( str10
=="\t from Elk Rapids to the point reminds me of miles" );
138 catch(std::exception
& fail
)
140 VERIFY( false ); // shouldn't throw
143 // ostream& operator<<(ostream&, const basic_string&)
144 std::ostringstream ostrs01
;
148 VERIFY( ostrs01
.str() == str01
);
150 catch(std::exception
& fail
)
155 std::string hello_world
;
156 std::cout
<< hello_world
;