33,311
社区成员
发帖
与我相关
我的任务
分享
在我的G++下运行正常
1 #include <iterator>
2 #include <iostream>
3 #include <algorithm>
4 #include <functional>
5 using namespace std;
6 int main()
7 {
8 int a[]={1,2,3,4,5,6,7,8},b[8];
9 copy(a,a+8,b);
10 reverse(a,a+8);
11 cout <<( *find(a,a+8,4)==4) <<endl;
12 copy(a,a+8,ostream_iterator <int>(cout," "));
13 cout <<endl;
14 copy(b,b+8,ostream_iterator <int>(cout," "));
15 cout <<endl;
16 }
OUTPUT:
1
8 7 6 5 4 3 2 1
1 2 3 4 5 6 7 8
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
void main()
{
int a[]={1,2,3,4,5,6,7,8},b[8];
copy(a,a+8,b);
reverse(a,a+8);
cout <<(find(a,a+8,4)-a)<<endl;
copy(a,a+8,ostream_iterator <int>(cout," "));
cout <<endl;
cout <<(find(b,b+8,4)-b)<<endl;
copy(b,b+8,ostream_iterator <int>(cout," "));
cout <<endl;
}
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
void main()
{
int a[]={1,2,3,4,5,6,7,8},b[8];
copy(a,a+8,b);
reverse(a,a+8);
cout <<( *find(a,a+8,4))<<endl;
copy(a,a+8,ostream_iterator <int>(cout," "));
cout <<endl;
cout <<( *find(b,b+8,4))<<endl;
copy(b,b+8,ostream_iterator <int>(cout," "));
cout <<endl;
}
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
int main()
{
int a[]={1,2,3,4,5,6,7,8},b[8];
copy(a,a+8,b);
reverse(a,a+8);
cout <<( find(a,a+8,4)-a) <<endl;
//copy(a,a+8,ostream_iterator <int>(cout," "));
for(int i=0;i<8;++i)
cout<<a[i]<<" ";
cout <<endl;
//copy(b,b+8,ostream_iterator <int>(cout," "));
for(int i=0;i<8;++i)
cout<<b[i]<<" ";
cout <<endl;
cout <<endl;
return 0;
}
//不好意思,那个ostream_iterator的好久没有用过,忘了。