g++-compiler bug? Problem with getline

Fred Richardson frichard@bbn.com
Sun Feb 1 06:21:00 GMT 1998


    (I forgot to CC egcs-bugs on this one):

>> g++ -o t t.C -W -Wall
>> t.C: In function `int main()':
>> t.C:9: no matching function for call to `getline (_IO_istream_withassign &, bas
>> ic_string,__default_alloc_template > &)'

I had the same problem.  I "fixed" it by using a slightly more
explicit signature: 

    string foo;
    getline(cin, foo, '\n');

For some reason this form seems to be resolved correctly.  

Here's a possible hint as to why all this might be happening.  I
noticed that the file:  

    include/g++/std/bastring.cc

is included when you use:

   #include <string>

but the prototype for the function "getline" in this file doesn't
specify a default value for "delim": 

    template <class charT, class traits, class Allocator>
    istream&
    getline (istream &is, basic_string <charT, traits, Allocator>& s, charT delim)

and this is the last prototype the compiler sees.  Perhaps this is
what is causing the problem...?

                    
                -Fred



More information about the Gcc-bugs mailing list