第十八章答案均由热心博友:王琪胜 提供
邮箱:wqs1639@gmail.com
如果对答案有疑问的可以发Email给我或者该博友,感谢大家一直以来的支持,
祝大家都能在编程中找到自己的最亮的那个闪光点。
————————————————————————————————————————————————————
18.4
//functor.cpp--using a-functor #include <iostream> #include <list> #include <iterator> #include <algorithm> int main(){ using namespace std; int vals[10]={50,100,90,180,60,210,415,88,188,201}; list<int> yadayada(vals,vals+10); list<int> etcetera(vals,vals+10); cout<<"Original lists:\n"; for_each(yadayada.begin(),yadayada.end(),[](int x){std::cout<<x<<" ";}); cout<<endl; for_each(etcetera.begin(),etcetera.end(),[](int x){std::cout<<x<<" ";}); cout<<endl; yadayada.remove_if([](int x){return x>100;}); etcetera.remove_if([](int x){return x>200;}); cout<<"Trimmed lists:\n"; for_each(yadayada.begin(),yadayada.end(),[](int x){std::cout<<x<<" ";}); cout<<endl; for_each(etcetera.begin(),etcetera.end(),[](int x){std::cout<<x<<" ";}); cout<<endl; return 0; }
——————————————————————————————————————————————————
//写的错误或者不好的地方请多多指导,可以在下面留言或者给我发邮件,指出我的错误以及不足,以便我修改,更好的分享给大家,谢谢。
转载请注明出处:https://www.royalchen.com/
author:royalchen
Email:royalchen@royalchen.com
———————————————————————————————————————————————————