2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / libstdc++-v3 / testsuite / 21_strings / basic_string / inserters_extractors / char / 1.cc
blobfb2721782c9215c8bcc190346e76fc327709b644
1 // 1999-07-01 bkoz
3 // Copyright (C) 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
4 //
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)
9 // any later version.
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,
19 // USA.
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.
27 #include <string>
28 #include <stdexcept>
29 #include <sstream>
30 #include <fstream>
31 #include <iostream>
32 #include <testsuite_hooks.h>
34 bool test01(void)
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;
47 std::string str10;
49 // istream& operator>>(istream&, string&)
50 std::istringstream istrs01(str01);
51 istrs01 >> str10;
52 VERIFY( str10 == str02 );
53 try
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
63 istrs01.clear();
64 istrs01 >> str10;
65 VERIFY( str10 == str03 );
66 istrs01.clear();
67 istrs01 >> str10;
68 VERIFY( str10 == str04 ); // sentry picks out the white spaces. .
70 std::istringstream istrs02(str05); // empty
71 istrs02 >> str10;
72 VERIFY( str10 == str04 );
74 // istream& getline(istream&, string&, char)
75 // istream& getline(istream&, string&)
76 try
78 istrs01.clear();
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
90 try
92 istrs01.clear();
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
104 try
106 istrs01.clear();
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
118 try
120 istrs01.clear();
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
132 try
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;
146 try
148 ostrs01 << str01;
149 VERIFY( ostrs01.str() == str01 );
151 catch(std::exception& fail)
153 VERIFY( false );
156 std::string hello_world;
157 std::cout << hello_world;
158 return test;
161 int main()
163 test01();
164 return 0;