发新话题
打印

各位,小弟有问题要请教!!!

各位,小弟有问题要请教!!!

#include <iostream>
#include <algorithm>
#include <iterator>

using std::cout;
using std::endl;

int main( )
{
    int v[ 20 ];
    for( int i = 0; i < 20; i++ ) {
        v[ i ] = i;
    }
            cout << std::find( v, v + 20,
                       std::bind2nd( d::equal_to<int>(), 9) );
        cout << endl;

VC7提示:
“bind2nd” : 不是“std”的成员
“equal_to” : 不是“std”的成员
看来是参数出了问题,不过指向数组的指针可以实做为叠代器的,为什么这个地方错了呢?
用std::copy( v, v+20, std:stream_iterator( cout, " " ) );编译运行都没用问题。
多谢了。      

TOP

写错了,用的是find_if算法。      

TOP

VC7 的 stl 不可取
用 gcc,你的代码应该看起来是这样(几乎没有修改):
复制内容到剪贴板
代码:
#include <iostream>
#include <algorithm>
#include <iterator>

using std::cout;
using std::endl;

int main( )
{
int v[20];
for(int i = 0; i < 20; i++) {
v[i] = i;
}
cout<<*std::find_if(v, v + 20, std::bind2nd(std::equal_to<int>(), 9));
cout<<endl;
}
      
-----------------------------------------
http://www.darkspy.org/blog

自大的人把宗教当迷信,无知的人把迷信当宗教

TOP

这样在可以在G++上编译成功,不过奇怪的是bind2nd,equal_to应该在functional头文件中的。
vc7中加入这个头文件就没有问题了。

用指针都不加反引,我还真可以的!!!!      

TOP

对呀!我也觉得bind2nd,equal_to应该在functional头文件中的,你没包含unctional,竟然会对!!

我试试!... ... ...      

TOP

发新话题