This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/28507] New: can't getline with basic_ifstream< unsigned char >
- From: "antonw03 at yahoo dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 27 Jul 2006 00:23:39 -0000
- Subject: [Bug c++/28507] New: can't getline with basic_ifstream< unsigned char >
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
I haven't had much experience with basic_ifstream, so please forgive me if this
is expected gcc behavior.
Observed behavior:
getline on an instance of basic_ifstream< unsigned char > fails to copy a line
of the source file to the buffer.
Expected behavior:
basic_ifstream< unsigned char > getline should work just like basic_ifstream<
char >'s getline (except for the difference in buffer character types).
Please save the example as main.cpp and just g++ main.cpp and execute ./a.out.
Here's the code example:
#include <fstream>
#include <iostream>
int main ( int argC, char ** const argV )
{
std::cout << "file content with std::basic_ifstream< char, std::char_traits<
char > :\n" << std::endl;
std::basic_ifstream< char, std::char_traits< char > > source( "main.cpp",
std::ios_base::in | std::ios_base::binary );
char buffer[ 8096 ] = {0};
while( source.getline( buffer, sizeof( buffer ), '\n' ) )
{
std::cout << buffer << std::endl;
}
source.close();
std::cout << "\n...END basic_ifstream< char > FILE...\n" << std::endl;
std::cout << "file content with std::basic_ifstream< unsigned char,
std::char_traits< unsigned char > :\n" << std::endl;
std::basic_ifstream< unsigned char, std::char_traits< unsigned char > >
uchar_source( "main.cpp", std::ios_base::in | std::ios_base::binary );
unsigned char uchar_buffer[ 8096 ] = {0};
while( uchar_source.getline( uchar_buffer, sizeof( uchar_buffer ), '\n' ) )
{
std::cout << uchar_buffer << std::endl;
}
uchar_source.close();
std::cout << "\n...END basic_ifstream< unsigned char > FILE...\n" <<
std::endl;
return 0;
}
I reproduced this behavior on a mac-mini OSX 10.4.7 with an intel processor
(gcc V 4.0.1) and also with an older intel freebsd box (gcc V 3.4.4).
--
Summary: can't getline with basic_ifstream< unsigned char >
Product: gcc
Version: 4.0.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: antonw03 at yahoo dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28507