L
lutorm
Hi everyone,
I'm trying to use istream_iterators to read a file consisting of pairs
of numbers. To do this, I wrote the following:
#include <fstream>
#include <vector>
#include <iterator>
using namespace std;
typedef std:air<double, double> float_pair;
std::istream& operator>> (std::istream& s,
std:air<double, double>& p)
{
s >> p.first;
s >> p.second;
return s;
}
main(){
ifstream file ("filename");
float_pair p;
file >> p; // this works
std::vector<float_pair> positions // but this doesn't
(istream_iterator<float_pair> (file),
(istream_iterator<float_pair> ()));
}
This used to work under my old compiler (KCC) but GCC 4.0 says it can't
find the operator<< (I think...) The full error message is below.
However, the operator works because when I try to read an individual
pair it works. Is there some magic that needs to be performed for the
istream_iterator to find the operator<<?
Thanks,
/Patrik Jonsson
[patrik@governator src]$ g++ optest.cc
/usr/lib/gcc/x86_64-redhat-linux/4.0.0/../../../../include/c++/4.0.0/bits/stream_iterator.h:
In member function 'void std::istream_iterator<_Tp, _CharT, _Traits,
_Dist>::_M_read() [with _Tp = float_pair, _CharT = char, _Traits =
std::char_traits<char>, _Dist = ptrdiff_t]':
/usr/lib/gcc/x86_64-redhat-linux/4.0.0/../../../../include/c++/4.0.0/bits/stream_iterator.h:68:
instantiated from 'std::istream_iterator<_Tp, _CharT, _Traits,
_Dist>::istream_iterator(std::basic_istream<_CharT, _Traits>&) [with
_Tp = float_pair, _CharT = char, _Traits = std::char_traits<char>,
_Dist = ptrdiff_t]'
optest.cc:24: instantiated from here
/usr/lib/gcc/x86_64-redhat-linux/4.0.0/../../../../include/c++/4.0.0/bits/stream_iterator.h:119:
error: no match for 'operator>>' in
'*((std::istream_iterator<float_pair, char, std::char_traits<char>,
ptrdiff_t>*)this)->std::istream_iterator<float_pair, char,
std::char_traits<char>, ptrdiff_t>::_M_stream >>
((std::istream_iterator<float_pair, char, std::char_traits<char>,
ptrdiff_t>*)this)->std::istream_iterator<float_pair, char,
std::char_traits<char>, ptrdiff_t>::_M_value'
/usr/lib/gcc/x86_64-redhat-linux/4.0.0/../../../../include/c++/4.0.0/istream:131:
note: candidates are: std::basic_istream<_CharT, _Traits>&
std::basic_istream<_CharT,
_Traits>:perator>>(std::basic_istream<_CharT, _Traits>&
(*)(std::basic_istream<_CharT, _Traits>&)) [with _CharT = char, _Traits
= std::char_traits<char>]
/usr/lib/gcc/x86_64-redhat-linux/4.0.0/../../../../include/c++/4.0.0/istream:134:
note: std::basic_istream<_CharT, _Traits>&
std::basic_istream<_CharT, _Traits>:perator>>(std::basic_ios<_CharT,
_Traits>& (*)(std::basic_ios<_CharT, _Traits>&)) [with _CharT = char,
_Traits = std::char_traits<char>]
/usr/lib/gcc/x86_64-redhat-linux/4.0.0/../../../../include/c++/4.0.0/istream:137:
note: std::basic_istream<_CharT, _Traits>&
std::basic_istream<_CharT, _Traits>:perator>>(std::ios_base&
(*)(std::ios_base&)) [with _CharT = char, _Traits =
std::char_traits<char>]
/usr/lib/gcc/x86_64-redhat-linux/4.0.0/../../../../include/c++/4.0.0/istream:169:
note: std::basic_istream<_CharT, _Traits>&
std::basic_istream<_CharT, _Traits>:perator>>(bool&) [with _CharT =
char, _Traits = std::char_traits<char>]
/usr/lib/gcc/x86_64-redhat-linux/4.0.0/../../../../include/c++/4.0.0/istream:172:
note: std::basic_istream<_CharT, _Traits>&
std::basic_istream<_CharT, _Traits>:perator>>(short int&) [with
_CharT = char, _Traits = std::char_traits<char>]
/usr/lib/gcc/x86_64-redhat-linux/4.0.0/../../../../include/c++/4.0.0/istream:175:
note: std::basic_istream<_CharT, _Traits>&
std::basic_istream<_CharT, _Traits>:perator>>(short unsigned int&)
[with _CharT = char, _Traits = std::char_traits<char>]
/usr/lib/gcc/x86_64-redhat-linux/4.0.0/../../../../include/c++/4.0.0/istream:178:
note: std::basic_istream<_CharT, _Traits>&
std::basic_istream<_CharT, _Traits>:perator>>(int&) [with _CharT =
char, _Traits = std::char_traits<char>]
/usr/lib/gcc/x86_64-redhat-linux/4.0.0/../../../../include/c++/4.0.0/istream:181:
note: std::basic_istream<_CharT, _Traits>&
std::basic_istream<_CharT, _Traits>:perator>>(unsigned int&) [with
_CharT = char, _Traits = std::char_traits<char>]
/usr/lib/gcc/x86_64-redhat-linux/4.0.0/../../../../include/c++/4.0.0/istream:184:
note: std::basic_istream<_CharT, _Traits>&
std::basic_istream<_CharT, _Traits>:perator>>(long int&) [with _CharT
= char, _Traits = std::char_traits<char>]
/usr/lib/gcc/x86_64-redhat-linux/4.0.0/../../../../include/c++/4.0.0/istream:187:
note: std::basic_istream<_CharT, _Traits>&
std::basic_istream<_CharT, _Traits>:perator>>(long unsigned int&)
[with _CharT = char, _Traits = std::char_traits<char>]
/usr/lib/gcc/x86_64-redhat-linux/4.0.0/../../../../include/c++/4.0.0/istream:191:
note: std::basic_istream<_CharT, _Traits>&
std::basic_istream<_CharT, _Traits>:perator>>(long long int&) [with
_CharT = char, _Traits = std::char_traits<char>]
/usr/lib/gcc/x86_64-redhat-linux/4.0.0/../../../../include/c++/4.0.0/istream:194:
note: std::basic_istream<_CharT, _Traits>&
std::basic_istream<_CharT, _Traits>:perator>>(long long unsigned
int&) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/lib/gcc/x86_64-redhat-linux/4.0.0/../../../../include/c++/4.0.0/istream:198:
note: std::basic_istream<_CharT, _Traits>&
std::basic_istream<_CharT, _Traits>:perator>>(float&) [with _CharT =
char, _Traits = std::char_traits<char>]
/usr/lib/gcc/x86_64-redhat-linux/4.0.0/../../../../include/c++/4.0.0/istream:201:
note: std::basic_istream<_CharT, _Traits>&
std::basic_istream<_CharT, _Traits>:perator>>(double&) [with _CharT =
char, _Traits = std::char_traits<char>]
/usr/lib/gcc/x86_64-redhat-linux/4.0.0/../../../../include/c++/4.0.0/istream:204:
note: std::basic_istream<_CharT, _Traits>&
std::basic_istream<_CharT, _Traits>:perator>>(long double&) [with
_CharT = char, _Traits = std::char_traits<char>]
/usr/lib/gcc/x86_64-redhat-linux/4.0.0/../../../../include/c++/4.0.0/istream:207:
note: std::basic_istream<_CharT, _Traits>&
std::basic_istream<_CharT, _Traits>:perator>>(void*&) [with _CharT =
char, _Traits = std::char_traits<char>]
/usr/lib/gcc/x86_64-redhat-linux/4.0.0/../../../../include/c++/4.0.0/istream:230:
note: std::basic_istream<_CharT, _Traits>&
std::basic_istream<_CharT,
_Traits>:perator>>(std::basic_streambuf<_CharT, _Traits>*) [with
_CharT = char, _Traits = std::char_traits<char>]
/usr/lib/gcc/x86_64-redhat-linux/4.0.0/../../../../include/c++/4.0.0/istream:688:
note: std::basic_istream<char, _Traits>&
std:perator>>(std::basic_istream<char, _Traits>&, unsigned char&)
[with _Traits = std::char_traits<char>]
/usr/lib/gcc/x86_64-redhat-linux/4.0.0/../../../../include/c++/4.0.0/istream:693:
note: std::basic_istream<char, _Traits>&
std:perator>>(std::basic_istream<char, _Traits>&, signed char&) [with
_Traits = std::char_traits<char>]
/usr/lib/gcc/x86_64-redhat-linux/4.0.0/../../../../include/c++/4.0.0/istream:729:
note: std::basic_istream<char, _Traits>&
std:perator>>(std::basic_istream<char, _Traits>&, unsigned char*)
[with _Traits = std::char_traits<char>]
/usr/lib/gcc/x86_64-redhat-linux/4.0.0/../../../../include/c++/4.0.0/istream:734:
note: std::basic_istream<char, _Traits>&
std:perator>>(std::basic_istream<char, _Traits>&, signed char*) [with
_Traits = std::char_traits<char>]
I'm trying to use istream_iterators to read a file consisting of pairs
of numbers. To do this, I wrote the following:
#include <fstream>
#include <vector>
#include <iterator>
using namespace std;
typedef std:air<double, double> float_pair;
std::istream& operator>> (std::istream& s,
std:air<double, double>& p)
{
s >> p.first;
s >> p.second;
return s;
}
main(){
ifstream file ("filename");
float_pair p;
file >> p; // this works
std::vector<float_pair> positions // but this doesn't
(istream_iterator<float_pair> (file),
(istream_iterator<float_pair> ()));
}
This used to work under my old compiler (KCC) but GCC 4.0 says it can't
find the operator<< (I think...) The full error message is below.
However, the operator works because when I try to read an individual
pair it works. Is there some magic that needs to be performed for the
istream_iterator to find the operator<<?
Thanks,
/Patrik Jonsson
[patrik@governator src]$ g++ optest.cc
/usr/lib/gcc/x86_64-redhat-linux/4.0.0/../../../../include/c++/4.0.0/bits/stream_iterator.h:
In member function 'void std::istream_iterator<_Tp, _CharT, _Traits,
_Dist>::_M_read() [with _Tp = float_pair, _CharT = char, _Traits =
std::char_traits<char>, _Dist = ptrdiff_t]':
/usr/lib/gcc/x86_64-redhat-linux/4.0.0/../../../../include/c++/4.0.0/bits/stream_iterator.h:68:
instantiated from 'std::istream_iterator<_Tp, _CharT, _Traits,
_Dist>::istream_iterator(std::basic_istream<_CharT, _Traits>&) [with
_Tp = float_pair, _CharT = char, _Traits = std::char_traits<char>,
_Dist = ptrdiff_t]'
optest.cc:24: instantiated from here
/usr/lib/gcc/x86_64-redhat-linux/4.0.0/../../../../include/c++/4.0.0/bits/stream_iterator.h:119:
error: no match for 'operator>>' in
'*((std::istream_iterator<float_pair, char, std::char_traits<char>,
ptrdiff_t>*)this)->std::istream_iterator<float_pair, char,
std::char_traits<char>, ptrdiff_t>::_M_stream >>
((std::istream_iterator<float_pair, char, std::char_traits<char>,
ptrdiff_t>*)this)->std::istream_iterator<float_pair, char,
std::char_traits<char>, ptrdiff_t>::_M_value'
/usr/lib/gcc/x86_64-redhat-linux/4.0.0/../../../../include/c++/4.0.0/istream:131:
note: candidates are: std::basic_istream<_CharT, _Traits>&
std::basic_istream<_CharT,
_Traits>:perator>>(std::basic_istream<_CharT, _Traits>&
(*)(std::basic_istream<_CharT, _Traits>&)) [with _CharT = char, _Traits
= std::char_traits<char>]
/usr/lib/gcc/x86_64-redhat-linux/4.0.0/../../../../include/c++/4.0.0/istream:134:
note: std::basic_istream<_CharT, _Traits>&
std::basic_istream<_CharT, _Traits>:perator>>(std::basic_ios<_CharT,
_Traits>& (*)(std::basic_ios<_CharT, _Traits>&)) [with _CharT = char,
_Traits = std::char_traits<char>]
/usr/lib/gcc/x86_64-redhat-linux/4.0.0/../../../../include/c++/4.0.0/istream:137:
note: std::basic_istream<_CharT, _Traits>&
std::basic_istream<_CharT, _Traits>:perator>>(std::ios_base&
(*)(std::ios_base&)) [with _CharT = char, _Traits =
std::char_traits<char>]
/usr/lib/gcc/x86_64-redhat-linux/4.0.0/../../../../include/c++/4.0.0/istream:169:
note: std::basic_istream<_CharT, _Traits>&
std::basic_istream<_CharT, _Traits>:perator>>(bool&) [with _CharT =
char, _Traits = std::char_traits<char>]
/usr/lib/gcc/x86_64-redhat-linux/4.0.0/../../../../include/c++/4.0.0/istream:172:
note: std::basic_istream<_CharT, _Traits>&
std::basic_istream<_CharT, _Traits>:perator>>(short int&) [with
_CharT = char, _Traits = std::char_traits<char>]
/usr/lib/gcc/x86_64-redhat-linux/4.0.0/../../../../include/c++/4.0.0/istream:175:
note: std::basic_istream<_CharT, _Traits>&
std::basic_istream<_CharT, _Traits>:perator>>(short unsigned int&)
[with _CharT = char, _Traits = std::char_traits<char>]
/usr/lib/gcc/x86_64-redhat-linux/4.0.0/../../../../include/c++/4.0.0/istream:178:
note: std::basic_istream<_CharT, _Traits>&
std::basic_istream<_CharT, _Traits>:perator>>(int&) [with _CharT =
char, _Traits = std::char_traits<char>]
/usr/lib/gcc/x86_64-redhat-linux/4.0.0/../../../../include/c++/4.0.0/istream:181:
note: std::basic_istream<_CharT, _Traits>&
std::basic_istream<_CharT, _Traits>:perator>>(unsigned int&) [with
_CharT = char, _Traits = std::char_traits<char>]
/usr/lib/gcc/x86_64-redhat-linux/4.0.0/../../../../include/c++/4.0.0/istream:184:
note: std::basic_istream<_CharT, _Traits>&
std::basic_istream<_CharT, _Traits>:perator>>(long int&) [with _CharT
= char, _Traits = std::char_traits<char>]
/usr/lib/gcc/x86_64-redhat-linux/4.0.0/../../../../include/c++/4.0.0/istream:187:
note: std::basic_istream<_CharT, _Traits>&
std::basic_istream<_CharT, _Traits>:perator>>(long unsigned int&)
[with _CharT = char, _Traits = std::char_traits<char>]
/usr/lib/gcc/x86_64-redhat-linux/4.0.0/../../../../include/c++/4.0.0/istream:191:
note: std::basic_istream<_CharT, _Traits>&
std::basic_istream<_CharT, _Traits>:perator>>(long long int&) [with
_CharT = char, _Traits = std::char_traits<char>]
/usr/lib/gcc/x86_64-redhat-linux/4.0.0/../../../../include/c++/4.0.0/istream:194:
note: std::basic_istream<_CharT, _Traits>&
std::basic_istream<_CharT, _Traits>:perator>>(long long unsigned
int&) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/lib/gcc/x86_64-redhat-linux/4.0.0/../../../../include/c++/4.0.0/istream:198:
note: std::basic_istream<_CharT, _Traits>&
std::basic_istream<_CharT, _Traits>:perator>>(float&) [with _CharT =
char, _Traits = std::char_traits<char>]
/usr/lib/gcc/x86_64-redhat-linux/4.0.0/../../../../include/c++/4.0.0/istream:201:
note: std::basic_istream<_CharT, _Traits>&
std::basic_istream<_CharT, _Traits>:perator>>(double&) [with _CharT =
char, _Traits = std::char_traits<char>]
/usr/lib/gcc/x86_64-redhat-linux/4.0.0/../../../../include/c++/4.0.0/istream:204:
note: std::basic_istream<_CharT, _Traits>&
std::basic_istream<_CharT, _Traits>:perator>>(long double&) [with
_CharT = char, _Traits = std::char_traits<char>]
/usr/lib/gcc/x86_64-redhat-linux/4.0.0/../../../../include/c++/4.0.0/istream:207:
note: std::basic_istream<_CharT, _Traits>&
std::basic_istream<_CharT, _Traits>:perator>>(void*&) [with _CharT =
char, _Traits = std::char_traits<char>]
/usr/lib/gcc/x86_64-redhat-linux/4.0.0/../../../../include/c++/4.0.0/istream:230:
note: std::basic_istream<_CharT, _Traits>&
std::basic_istream<_CharT,
_Traits>:perator>>(std::basic_streambuf<_CharT, _Traits>*) [with
_CharT = char, _Traits = std::char_traits<char>]
/usr/lib/gcc/x86_64-redhat-linux/4.0.0/../../../../include/c++/4.0.0/istream:688:
note: std::basic_istream<char, _Traits>&
std:perator>>(std::basic_istream<char, _Traits>&, unsigned char&)
[with _Traits = std::char_traits<char>]
/usr/lib/gcc/x86_64-redhat-linux/4.0.0/../../../../include/c++/4.0.0/istream:693:
note: std::basic_istream<char, _Traits>&
std:perator>>(std::basic_istream<char, _Traits>&, signed char&) [with
_Traits = std::char_traits<char>]
/usr/lib/gcc/x86_64-redhat-linux/4.0.0/../../../../include/c++/4.0.0/istream:729:
note: std::basic_istream<char, _Traits>&
std:perator>>(std::basic_istream<char, _Traits>&, unsigned char*)
[with _Traits = std::char_traits<char>]
/usr/lib/gcc/x86_64-redhat-linux/4.0.0/../../../../include/c++/4.0.0/istream:734:
note: std::basic_istream<char, _Traits>&
std:perator>>(std::basic_istream<char, _Traits>&, signed char*) [with
_Traits = std::char_traits<char>]