Algoritmy “remove”

{“https:\/\/www.jdoodle.com\/a\/cmX?format=text”:”#include <iostream>\n#include <string>\n#include <algorithm>\nusing namespace std;\n\nint main() {\n string s = "Hello, world !!!!";\n cout << s << endl;\n remove(s.begin(), s.end(), ‘l’);\n cout << s << endl;\n}\n”,”https:\/\/www.jdoodle.com\/a\/cn1?format=text”:”#include <iostream>\n#include <vector>\n#include <algorithm>\nusing namespace std;\n\ntemplate<typename C>\nvoid print(C c) {\n for(auto val : c)\n cout << val << ";";\n cout << endl;\n}\n\nint main() {\n vector<int> data;\n auto generator = []() {\n static int val = 0;\n return ++val;\n };\n generate_n(back_inserter(data), 20, generator);\n \n print(data);\n remove_if(data.begin(), data.end(), [](int item) { return item % 2 == 0; });\n print(data);\n return 0;\n}\n”,”https:\/\/www.jdoodle.com\/a\/cn3?format=text”:”#include <iostream>\n#include <string>\n#include <algorithm>\nusing namespace std;\n\nint main() {\n string s = "Hello, world !!!!";\n string s2;\n remove_copy(s.begin(), s.end(), back_inserter(s2), ‘l’);\n cout << s << endl;\n cout << s2 << endl;\n}\n”,”https:\/\/www.jdoodle.com\/a\/cn6?format=text”:”#include <iostream>\n#include <vector>\n#include <algorithm>\nusing namespace std;\n\ntemplate<typename C>\nvoid print(C c) {\n for(auto val : c)\n cout << val << ";";\n cout << endl;\n}\n\nint main() {\n vector<int> data;\n auto generator = []() {\n static int val = 0;\n return ++val;\n };\n generate_n(back_inserter(data), 20, generator);\n \n vector<int> data2;\n remove_copy_if(data.begin(), data.end(), back_inserter(data2), \n [](int item) { return item % 2 == 0; });\n print(data);\n print(data2);\n return 0;\n}\n”}


Algoritmy “remove”
Ohodnoťte tento článek