|
- #include <iostream>
- #include <set>
- #include <algorithm>
- #include <iterator>
-
- using namespace std;
- int main() {
- set<int> col1;
- for(int i=0;i<10;i++) {
- col1.insert(i);
- }
-
-
- transform(col1.begin(),col1.end(),
- col1.begin(),
- bind2nd (multiplies<int>(), 2));
- copy(col1.begin(),col1.end(), ostream_iterator<int>(cout," "));
- cout<<endl;
- }
复制代码
在visual c++ 2005下面compile通过
cl -nologo -EHsc -GR -Zc:forScope -Zc:wchar_t -Fetransform transform2.cpp
在cygwin下面出错
$ g++ -o transform transform2.cpp
/usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/bits/stl_algo.h: In function `_Out
putIterator std::transform(_InputIterator, _InputIterator, _OutputIterator, _Una
ryOperation) [with _InputIterator = std::_Rb_tree_const_iterator<int>, _OutputIt
erator = std::_Rb_tree_const_iterator<int>, _UnaryOperation = std::binder2nd<std
::multiplies<int> >]':
transform2.cpp:18: instantiated from here
/usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/bits/stl_algo.h:789: error: assign
ment of read-only location
mingw下面同样的问题
D:\cpp>g++ -otransform2 transform2.cpp
d:/mingw/bin/../lib/gcc/mingw32/3.4.5/../../../../include/c++/3.4.5/bits/stl_alg
o.h: In function `_OutputIterator std::transform(_InputIterator, _InputIterator,
_OutputIterator, _UnaryOperation) [with _InputIterator = std::_Rb_tree_const_it
erator<int>, _OutputIterator = std::_Rb_tree_const_iterator<int>, _UnaryOperatio
n = std::binder2nd<std::multiplies<int> >]':
transform2.cpp:18: instantiated from here
d:/mingw/bin/../lib/gcc/mingw32/3.4.5/../../../../include/c++/3.4.5/bits/stl_alg
o.h:789: error: assignment of read-only location
请高人指点一二。不胜感激。 |
|