Commit a2554733 by Danny Smith Committed by Benjamin Kosnik

istream.tcc (basic_istream::ignore): Use sbumpc, not snextc.


2002-08-08  Danny Smith  <dannysmith@users.sourceforge.net>
            Benjamin Kosnik  <bkoz@redhat.com>

	* include/bits/istream.tcc (basic_istream::ignore): Use sbumpc,
	not snextc.

Co-Authored-By: Benjamin Kosnik <bkoz@redhat.com>

From-SVN: r56153
parent 55202bee
2002-08-08 Danny Smith <dannysmith@users.sourceforge.net>
Benjamin Kosnik <bkoz@redhat.com>
* include/bits/istream.tcc (basic_istream::ignore): Use sbumpc,
not snextc.
* testsuite/27_io/narrow_stream_objects.cc (test10): Add.
2002-08-07 John David Anglin <dave@hiauly1.hia.nrc.ca> 2002-08-07 John David Anglin <dave@hiauly1.hia.nrc.ca>
* libsupc++/Makefile.am (LTCOMPILE): Add LIBSUPCXX_PICFLAGS. * libsupc++/Makefile.am (LTCOMPILE): Add LIBSUPCXX_PICFLAGS.
......
...@@ -722,23 +722,18 @@ namespace std ...@@ -722,23 +722,18 @@ namespace std
{ {
const int_type __eof = traits_type::eof(); const int_type __eof = traits_type::eof();
__streambuf_type* __sb = this->rdbuf(); __streambuf_type* __sb = this->rdbuf();
int_type __c = __sb->sgetc(); int_type __c;
__n = min(__n, numeric_limits<streamsize>::max()); __n = min(__n, numeric_limits<streamsize>::max());
while (_M_gcount < __n while (_M_gcount < __n
&& !traits_type::eq_int_type(__c, __eof) && !traits_type::eq_int_type(__c = __sb->sbumpc(), __eof))
&& !traits_type::eq_int_type(__c, __delim))
{ {
__c = __sb->snextc();
++_M_gcount; ++_M_gcount;
if (traits_type::eq_int_type(__c, __delim))
break;
} }
if (traits_type::eq_int_type(__c, __eof)) if (traits_type::eq_int_type(__c, __eof))
this->setstate(ios_base::eofbit); this->setstate(ios_base::eofbit);
else if (traits_type::eq_int_type(__c, __delim))
{
__sb->sbumpc();
++_M_gcount;
}
} }
catch(exception& __fail) catch(exception& __fail)
{ {
......
...@@ -66,7 +66,8 @@ ...@@ -66,7 +66,8 @@
#include <cstdlib> #include <cstdlib>
#include <cstring> #include <cstring>
#include <ctime> #include <ctime>
#include <testsuite_hooks.h> //#include <testsuite_hooks.h>
#define VERIFY(x) x
// Include iostream last, just to make is as difficult as possible to // Include iostream last, just to make is as difficult as possible to
// properly initialize the standard iostream objects. // properly initialize the standard iostream objects.
...@@ -116,19 +117,20 @@ void test03() ...@@ -116,19 +117,20 @@ void test03()
// Interactive test, to be exercised as follows: // Interactive test, to be exercised as follows:
// assign stderr to stdout in shell command line, // assign stderr to stdout in shell command line,
// pipe stdout to cat process and/or redirect stdout to file. // pipe stdout to cat process and/or redirect stdout to file.
// "hello fine world\n" should be written to stdout in proper order. // a.out >& output
// This is a version of the scott snyder test taken from: // "hello fine world\n" should be written to stdout, and output, in
// http://gcc.gnu.org/ml/libstdc++/1999-q4/msg00108.html // proper order. This is a version of the scott snyder test taken
// from: http://gcc.gnu.org/ml/libstdc++/1999-q4/msg00108.html
void test04() void test04()
{ {
using namespace std; using namespace std;
cout << "hello "; cout << "hello ";
cout.flush (); cout.flush();
cerr << "fine "; cerr << "fine ";
cerr.flush (); cerr.flush();
cout << "world" << endl; cout << "world" << endl;
cout.flush (); cout.flush();
} }
// Interactive test, to be exercised as follows: // Interactive test, to be exercised as follows:
...@@ -138,7 +140,7 @@ void test04() ...@@ -138,7 +140,7 @@ void test04()
// depending upon buffering mode enforced. // depending upon buffering mode enforced.
void test05() void test05()
{ {
std::cout << "hello" << ' ' << "world" <<std::endl; std::cout << "hello" << ' ' << "world" << std::endl;
std::cout << "Enter your name: "; std::cout << "Enter your name: ";
std::string s; std::string s;
std::cin >> s; std::cin >> s;
...@@ -169,7 +171,7 @@ void test06() ...@@ -169,7 +171,7 @@ void test06()
void test07() void test07()
{ {
bool test = true; bool test = true;
std::cout << "Please, enter 'test':"; std::cout << "Enter 'test':";
std::string s; std::string s;
std::getline(std::cin, s, '\n'); std::getline(std::cin, s, '\n');
VERIFY( s == "test" ); VERIFY( s == "test" );
...@@ -188,10 +190,21 @@ void test08() ...@@ -188,10 +190,21 @@ void test08()
void test09() void test09()
{ {
bool test = true; bool test = true;
std::cout << "Enter name: "; std::cout << "Enter favorite beach: ";
std::cin.ignore(2048, '\n'); std::cin.ignore(2048, '\n');
} }
// http://gcc.gnu.org/ml/libstdc++/2002-08/msg00060.html
// Should only have to hit enter once.
void
test10()
{
using namespace std;
cout << "Press ENTER once\n";
cin.ignore(1);
cout << "_M_gcount: "<< cin.gcount() << endl;
}
int int
main() main()
{ {
...@@ -205,5 +218,6 @@ main() ...@@ -205,5 +218,6 @@ main()
// test07(); // test07();
// test08(); // test08();
// test09(); // test09();
// test10();
return 0; return 0;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment