1 void func(forward_list<string>& flst, const string& s1, const string& s2) { 2 auto bb = flst.before_begin(); 3 bool flag = false; 4 for (auto j : flst) { 5 if (j == s1) 6 { flag = true; break; } 7 } 8 for (auto i = flst.begin(); i != flst.end(); ++i) 9 { 10 if (*i == s1) 11 { 12 bb = i; 13 flst.insert_after(bb, s2); 14 } 15 else 16 bb = i; 17 } 18 if (flag == false) { flst.insert_after(bb, s2); } 19 } 20 int main(int argc, char* argv[]) 21 { 22 forward_list<string>f{ "1","2","3","4" }; 23 func(f, "5", "6"); 24 for (auto i : f) 25 cout << i << endl; 26 }
10.20:
vector<string>s{ "summary","which","countwhat" }; auto a = count_if(s.begin(), s.end(), [](string ss) {return ss.size() > 6 ? true : false;}); cout << a << endl;
10.21:
auto s = 10; auto a = [&s]() { --s; return s != 0 ? 1 : 0;}; while (a()) cout << s << ends;