c++ primer 9.28 标准答案

http://blog.youkuaiyun.com/chenxun_2010/article/details/37731883


百度后找到了 9.28的答案。。为防止此链接丢失,,还是粘上去吧


[cpp]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. #include<iostream>  
  2. #include<vector>  
  3. #include<string>  
  4. #include<deque>  
  5. #include<list>  
  6. #include<forward_list>  
  7. using namespace std;  
  8.   
  9. void my_insert(forward_list<string> &f, const string &s1,const string &s2)  
  10. {  
  11.     auto prev = f.before_begin();  
  12.     auto curr = f.begin();  
  13.     while (curr != f.end())  
  14.     {  
  15.         if (*curr == s1)  
  16.         {   f.insert_after(curr, s2);  
  17.             return;  
  18.         }  
  19.         else  
  20.         {  
  21.             prev = curr;  
  22.             ++curr;  
  23.         }  
  24.     }  
  25.     f.insert_after(prev,s2);  
  26.     return;  
  27. }//这里必须有return,Google很好用!  
  28.   
  29. int main()  
  30. {  
  31.     forward_list<string> my_vector{ "chen""xun""is""an","student" };  
  32.     my_insert(my_vector, "an""excellent");  
  33.     my_insert(my_vector, "student"",oh yeah!");  
  34.     for (auto &a : my_vector)  
  35.         cout << a << ' ';  
  36.     cout << endl;  
  37.     return 0;  
  38. }  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值