This is the mail archive of the libstdc++@sourceware.cygnus.com mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

new woes with istream



alright, I've got a new test case which I think exposes another bug.

this time it's in istream::getline().  it does not properly
fill up the char * array with the first line of a file.
I think the problem is somewhere around:
libstdc++/H-libstdc++/include/g++-v3/bits/std_istream.h:370
  if (this->rdbuf()->_M_fctype_buf->is(__delim, __bufval))
	{
	  this->rdbuf()->sputbackc(__bufval);		      
	  break;
	}

the first time this is reached, __bufval holds the contents of the first
character of the file (a valid char) and for some reason it thinks it's
the delim char and puts it back on the stream (???)
I don't know enough about the guts of libstdc++ to say for sure.

To test, first create a file "1gcn.pdbrun" with at least one line of text in
it.

Then compile and run this program with the latest libstdc++ CVS:

#include <sstream>
#include <fstream>
#include <iostream>

int main(int argc, char **argv)
{
  const char *filename="1gcn.pdbrun";
  std::ifstream *is;
  is = new ifstream(filename);

  if (!*is) {
    std::ostringstream es;
    es << "Unable to open " << filename << " for reading.";
    std::cerr << es;
    exit(1);
  }

  char foo[500];
  std::cout << is->good() << std::endl;
  is->getline(foo, 500);
  std::cout << is->good() << std::endl;

  std::cout << "Read line: '" << foo << "'" << std::endl;
  return 0;
}

I get the output:

dek@www:~/src/TestStdC++
:./test11

1
0
Read line: ''


On our tru64 and irix boxes this code works just fine... 

(note, using string s; ::getline(is, s); works OK!!)
Dave
-----------------------------------------------------------------------------
Email: dek@cgl.ucsf.edu   David Konerding   WWW: http://picasso.ucsf.edu/~dek
-----------------------------------------------------------------------------

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]