//利用copy函数快速输出向量容器中的数据 vector<int> v; intn=5; cout<<"请输入"<<n<<"个整数"<<endl; inti=0; intnValue; while(i<n) { cin>>nValue; v.push_back(nValue); ++i; } //输出 cout<<"向量容器中的数据为:"<<endl; copy(v.begin(),v.end(),ostream_iterator<int>(cout...
rotate(v1.begin(), middle, v1.end()); cout<< "以4为中心环移(roate) : "; copy(v1.begin(), v1.end(), ostream_iterator<int>(cout, " ")); cout<< endl; list<int> v2(a, a + 8); list<int> v3; middle = v2.begin(); cout<< "以4为中心环移v2-->v3(reverse_copy) :...
vector<int> v(a, a + 8); while (!_kbhit()) { copy(v.begin(), v.end(), ostream_iterator<int>(cout, " ")); rotate(v.begin(), v.begin() + 1, v.end()); delay(); cout << endl; } return 0; } 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 1...
cout<< "原始数据: "; copy(a, a + 9, ostream_iterator<int>(cout, " ")); cout<< endl; cout<< "原数据2用10代替(replace): "; vector<int> v1(a, a + 9); replace(v1.begin(), v1.end(), 2, 10); copy(v1.begin(), v1.end(), ostream_iterator<int>(cout, " ")); ...
ostream_iterator<int, char> out_iter(cout, " "); copy(dice.begin(), dice.end(), out_iter); cout << endl; // 反向输出第一种形式 copy(dice.rbegin(), dice.rend(), out_iter); cout << endl; // 反向输出第二种形式 for (auto ri = dice.rbegin(); ri != dice.rend(); ++ri)...
我们将频繁的使用copy函数,通过ostream迭代器来输出容器中的元素。 当然,我们可以直接在copy函数中指定一个ostream迭代器,因此对于上面的例子,可以直接写为: copy(vecList.begin(), vecList.end(), ostream_iterator<int>(cout, " ")); 最后,语句:
cout<<endl; replace_if(v.begin(),v.end(),bind2nd(greater<int>(),5),10086);//把大于五的都换成10086 copy(v.begin(),v.end(),ostream_iterator<int>(cout," ")); cout<<endl; replace_if(v.begin(),v.end(),not1(bind2nd(modulus<int>(),2)),222);//把偶数换成222 ...
reverse_copy(v.begin(),v.end(),ostream_iterator<int>(cout," ")); cout<<endl; system("pause"); return 0; } //rotate rotate_copy #include<iostream> #include<string> #include<algorithm> #include<functional> #include<vector> using namespace std; ...
intmain() { intarr[]={1,3,5,2,4,6}; //从int*复制到ostream copy(arr,arr+6,ostream_iterator(cout,"")); cout<<endl; vectorv(7,0);//提前为vector分配空间 //从int*复制到vector vector::iteratorlast=copy(arr,arr+6,v.begin()); copy(v.begin(),last,ostream_iterator(cout,""));...
std::vector<bool> v; std::transform( m.begin(), m.end(), std::back_inserter( v ), second(m) ); std::transform( m.begin(), m.end(), std::ostream_iterator<bool>( std::cout, ";" ), second(m) ); } Very generic, remember to give him credit if you find it useful. Sha...