This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/45254] New: data declaration parse error


$cat main.cc && g++ -v && g++ -o m main.cc
#include <iostream>
#include <algorithm>
#include <fstream>
#include <iterator>

using namespace std;

struct record
{
        int date;
        int key[5];
};

std::istream&
operator >> ( std::istream& lhs, record& rhs )
{
        lhs >> rhs.date;
        lhs >> rhs.key[0];
        lhs >> rhs.key[1];
        lhs >> rhs.key[2];
        lhs >> rhs.key[3];
        lhs >> rhs.key[4];

        return lhs;
}

std::ostream&
operator << ( std::ostream& lhs, const record& rhs )
{
        lhs << rhs.date << "\n";
        lhs << "\t" << rhs.key[0] << "\n";
        lhs << "\t" << rhs.key[1] << "\n";
        lhs << "\t" << rhs.key[2] << "\n";
        lhs << "\t" << rhs.key[3] << "\n";
        lhs << "\t" << rhs.key[4] << "\n";

        return lhs;
}

int main()
{
        copy(   (istream_iterator<record>(cin)),
                        (istream_iterator<record>()),
                        (ostream_iterator<record>((ofstream("record.dat",
ios::out)), "\n"))
                );

        //istream_iterator<record> r1(cin);
        //istream_iterator<record> rn;
        //ofstream o("record.dat", ios::out);
        //ostream_iterator<record> o1(o, "\n");
        //copy( r1, rn, o1 );

        return 0;
}

Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/i686-pc-linux-gnu/4.5.0/lto-wrapper
Target: i686-pc-linux-gnu
Configured with: ../configure --prefix=/usr
--enable-languages=c,c++,fortran,objc,obj-c++,ada --enable-shared
--enable-threads=posix --enable-__cxa_atexit --enable-clocale=gnu
--enable-gnu-unique-object --enable-lto --enable-plugin --disable-multilib
--disable-libstdcxx-pch --with-system-zlib --with-ppl --with-cloog
--libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man
--infodir=/usr/share/info
Thread model: posix
gcc version 4.5.0 20100610 (prerelease) (GCC)
main.cc: In function ¡®int main()¡¯:
main.cc:44:70: error: no matching function for call to
¡®std::ostream_iterator<record>::ostream_iterator(std::ofstream, const char
[2])¡¯
/usr/lib/gcc/i686-pc-linux-gnu/4.5.0/../../../../include/c++/4.5.0/bits/stream_iterator.h:185:7:
note: candidates are: std::ostream_iterator<_Tp, _CharT,
_Traits>::ostream_iterator(const std::ostream_iterator<_Tp, _CharT, _Traits>&)
[with _Tp = record, _CharT = char, _Traits = std::char_traits<char>,
std::ostream_iterator<_Tp, _CharT, _Traits> = std::ostream_iterator<record>]
/usr/lib/gcc/i686-pc-linux-gnu/4.5.0/../../../../include/c++/4.5.0/bits/stream_iterator.h:181:7:
note:                 std::ostream_iterator<_Tp, _CharT,
_Traits>::ostream_iterator(std::ostream_iterator<_Tp, _CharT,
_Traits>::ostream_type&, const _CharT*) [with _Tp = record, _CharT = char,
_Traits = std::char_traits<char>, std::ostream_iterator<_Tp, _CharT,
_Traits>::ostream_type = std::basic_ostream<char>]
/usr/lib/gcc/i686-pc-linux-gnu/4.5.0/../../../../include/c++/4.5.0/bits/stream_iterator.h:169:7:
note:                 std::ostream_iterator<_Tp, _CharT,
_Traits>::ostream_iterator(std::ostream_iterator<_Tp, _CharT,
_Traits>::ostream_type&) [with _Tp = record, _CharT = char, _Traits =
std::char_traits<char>, std::ostream_iterator<_Tp, _CharT,
_Traits>::ostream_type = std::basic_ostream<char>]


-- 
           Summary: data declaration parse error
           Product: gcc
           Version: 4.5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: wanng dot fenng at gmail dot com
 GCC build triplet:  ../configure --prefix=/usr --enable-
                    languages=c,c++,fortran,obj
GCC target triplet: i686-pc-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45254


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