G
grahamo
Hi,
I am trying to use STL copy routine to stream the my user defined type
to std out. I am using a standard ostream_iterator object in
conjunction with my type (called employee) which has
friend std:stream& operator<< (std:stream &os, const employee&
e);
correctly implemented and I am therefore able to do things like;
cout << employee_instance << endl;
however I have a collection of my employee objects populating an STL
map and what I now want to be able to do is this;
copy (my_employee_map.begin(), my_employee_map.end(),
ostream_iterator<employee> (cout, " ") );
however I am getting all sorts of compile time errors. (they're below
but you probably don't want to see them
I am fairly sure there's something needed in my employee class in
order to get the line of code;
copy (my_employee_map.begin(), my_employee_map.end(),
ostream_iterator<employee> (cout, " ") );
to work correctly.
Any ideas?
thanks much,
GrahamO
Compiler: gnu
Building Makefile: "C:\cygwin\projects\stl\Makefile.win"
Executing make...
make.exe -f "C:\cygwin\projects\stl\Makefile.win" all
g++.exe -c main.cpp -o main.o -I"C:/cygwin/usr/include"
In file included from /usr/include/c++/3.3.1/backward/defalloc.h:58,
from main.cpp:10:
/usr/include/c++/3.3.1/backward/backward_warning.h:32:2: warning:
#warning This file includes at least one deprecated or antiquated
header. Please consider using one of the 32 headers found in section
17.4.1.2 of the C++ standard. Examples include substituting the <X>
header for the <X.h> header for C++ includes, or <sstream> instead of
the deprecated header <strstream.h>. To disable this warning use
-Wno-deprecated.
/usr/include/c++/3.3.1/bits/stl_algobase.h: In function `_OutputIter
std::__copy(_InputIter, _InputIter, _OutputIter,
std::input_iterator_tag)
[with _InputIter = std::_Rb_tree_iterator<std:air<const int,
employee>,
std:air<const int, employee>&, std:air<const int, employee>*>,
_OutputIter = std:stream_iterator<EMPLOYEE, char,
`_OutputIter std::__copy_aux2(_InputIter, _InputIter, _OutputIter,
__false_type) [with _InputIter =
std::_Rb_tree_iterator<std:air<const int, employee>, std:air<const
int, employee>&, std:air<const int, employee>*>, _OutputIter =
std:stream_iterator<EMPLOYEE, char, std::char_traits<char> >]'
/usr/include/c++/3.3.1/bits/stl_algobase.h:303: instantiated from
`_OutputIter std::__copy_ni2(_InputIter, _InputIter, _OutputIter,
__false_type) [with _InputIter =
std::_Rb_tree_iterator<std:air<const int, employee>, std:air<const
int, employee>&, std:air<const int, employee>*>, _OutputIter =
std:stream_iterator<EMPLOYEE, char, std::char_traits<char> >]'
/usr/include/c++/3.3.1/bits/stl_algobase.h:323: instantiated from
`_OutputIter std::__copy_ni1(_InputIter, _InputIter, _OutputIter,
__false_type) [with _InputIter =
std::_Rb_tree_iterator<std:air<const int, employee>, std:air<const
int, employee>&, std:air<const int, employee>*>, _OutputIter =
std:stream_iterator<EMPLOYEE, char, std::char_traits<char> >]'
/usr/include/c++/3.3.1/bits/stl_algobase.h:349: instantiated from
`_OutputIter std::copy(_InputIter, _InputIter, _OutputIter) [with
_InputIter = std::_Rb_tree_iterator<std:air<const int, employee>,
std:air<const int, employee>&, std:air<const int, employee>*>,
_OutputIter = std:stream_iterator<EMPLOYEE, char,
std::char_traits<char> >]'
main.cpp:296: instantiated from here
/usr/include/c++/3.3.1/bits/stl_algobase.h:228: error: no match for
'operator='
in '(&__result)->std:stream_iterator<_Tp, _CharT,
_Traits>:perator*()
[with _Tp = EMPLOYEE, _CharT = char, _Traits =
std::char_traits<char>]() =
(&__first)->std::_Rb_tree_iterator<_Val, _Ref, _Ptr>:perator*()
const
[with _Val = std:air<const int, employee>, _Ref = std:air<const
int,
employee>&, _Ptr = std:air<const int, employee>*]()'
/usr/include/c++/3.3.1/bits/stream_iterator.h:140: error: candidates
are:
std:stream_iterator<_Tp, _CharT, _Traits>&
std:stream_iterator<_Tp,
_CharT, _Traits>:perator=(const _Tp&) [with _Tp = EMPLOYEE,
_CharT = char,
_Traits = std::char_traits<char>]
/usr/include/c++/3.3.1/bits/stream_iterator.h:119: error:
make: *** [main.o] Error 1
Execution terminated
I am trying to use STL copy routine to stream the my user defined type
to std out. I am using a standard ostream_iterator object in
conjunction with my type (called employee) which has
friend std:stream& operator<< (std:stream &os, const employee&
e);
correctly implemented and I am therefore able to do things like;
cout << employee_instance << endl;
however I have a collection of my employee objects populating an STL
map and what I now want to be able to do is this;
copy (my_employee_map.begin(), my_employee_map.end(),
ostream_iterator<employee> (cout, " ") );
however I am getting all sorts of compile time errors. (they're below
but you probably don't want to see them
I am fairly sure there's something needed in my employee class in
order to get the line of code;
copy (my_employee_map.begin(), my_employee_map.end(),
ostream_iterator<employee> (cout, " ") );
to work correctly.
Any ideas?
thanks much,
GrahamO
Compiler: gnu
Building Makefile: "C:\cygwin\projects\stl\Makefile.win"
Executing make...
make.exe -f "C:\cygwin\projects\stl\Makefile.win" all
g++.exe -c main.cpp -o main.o -I"C:/cygwin/usr/include"
In file included from /usr/include/c++/3.3.1/backward/defalloc.h:58,
from main.cpp:10:
/usr/include/c++/3.3.1/backward/backward_warning.h:32:2: warning:
#warning This file includes at least one deprecated or antiquated
header. Please consider using one of the 32 headers found in section
17.4.1.2 of the C++ standard. Examples include substituting the <X>
header for the <X.h> header for C++ includes, or <sstream> instead of
the deprecated header <strstream.h>. To disable this warning use
-Wno-deprecated.
/usr/include/c++/3.3.1/bits/stl_algobase.h: In function `_OutputIter
std::__copy(_InputIter, _InputIter, _OutputIter,
std::input_iterator_tag)
[with _InputIter = std::_Rb_tree_iterator<std:air<const int,
employee>,
std:air<const int, employee>&, std:air<const int, employee>*>,
_OutputIter = std:stream_iterator<EMPLOYEE, char,
/usr/include/c++/3.3.1/bits/stl_algobase.h:260: instantiated fromstd::char_traits said:
`_OutputIter std::__copy_aux2(_InputIter, _InputIter, _OutputIter,
__false_type) [with _InputIter =
std::_Rb_tree_iterator<std:air<const int, employee>, std:air<const
int, employee>&, std:air<const int, employee>*>, _OutputIter =
std:stream_iterator<EMPLOYEE, char, std::char_traits<char> >]'
/usr/include/c++/3.3.1/bits/stl_algobase.h:303: instantiated from
`_OutputIter std::__copy_ni2(_InputIter, _InputIter, _OutputIter,
__false_type) [with _InputIter =
std::_Rb_tree_iterator<std:air<const int, employee>, std:air<const
int, employee>&, std:air<const int, employee>*>, _OutputIter =
std:stream_iterator<EMPLOYEE, char, std::char_traits<char> >]'
/usr/include/c++/3.3.1/bits/stl_algobase.h:323: instantiated from
`_OutputIter std::__copy_ni1(_InputIter, _InputIter, _OutputIter,
__false_type) [with _InputIter =
std::_Rb_tree_iterator<std:air<const int, employee>, std:air<const
int, employee>&, std:air<const int, employee>*>, _OutputIter =
std:stream_iterator<EMPLOYEE, char, std::char_traits<char> >]'
/usr/include/c++/3.3.1/bits/stl_algobase.h:349: instantiated from
`_OutputIter std::copy(_InputIter, _InputIter, _OutputIter) [with
_InputIter = std::_Rb_tree_iterator<std:air<const int, employee>,
std:air<const int, employee>&, std:air<const int, employee>*>,
_OutputIter = std:stream_iterator<EMPLOYEE, char,
std::char_traits<char> >]'
main.cpp:296: instantiated from here
/usr/include/c++/3.3.1/bits/stl_algobase.h:228: error: no match for
'operator='
in '(&__result)->std:stream_iterator<_Tp, _CharT,
_Traits>:perator*()
[with _Tp = EMPLOYEE, _CharT = char, _Traits =
std::char_traits<char>]() =
(&__first)->std::_Rb_tree_iterator<_Val, _Ref, _Ptr>:perator*()
const
[with _Val = std:air<const int, employee>, _Ref = std:air<const
int,
employee>&, _Ptr = std:air<const int, employee>*]()'
/usr/include/c++/3.3.1/bits/stream_iterator.h:140: error: candidates
are:
std:stream_iterator<_Tp, _CharT, _Traits>&
std:stream_iterator<_Tp,
_CharT, _Traits>:perator=(const _Tp&) [with _Tp = EMPLOYEE,
_CharT = char,
_Traits = std::char_traits<char>]
/usr/include/c++/3.3.1/bits/stream_iterator.h:119: error:
std::char_traits<char> >&)std::ostream_iterator said::perator=(const std:stream_iterator<EMPLOYEE, char,
make: *** [main.o] Error 1
Execution terminated