{"id":14747,"date":"2024-06-05T20:19:42","date_gmt":"2024-06-05T17:19:42","guid":{"rendered":"https:\/\/elzero.org\/?p=14747"},"modified":"2024-06-05T20:19:42","modified_gmt":"2024-06-05T17:19:42","slug":"implement-functions-with-cpp-push-items-to-vector","status":"publish","type":"post","link":"https:\/\/elzero.org\/old\/implement-functions-with-cpp-push-items-to-vector\/","title":{"rendered":"Push Items To Vector"},"content":{"rendered":"<h3>\u0645\u062d\u062a\u0648\u0649 \u0627\u0644\u062f\u0631\u0633<\/h3>\r\n\r\n<script type=\"text\/plain\" class=\"language-c\">\r\n#include <iostream>\r\n#include <vector>\r\nusing namespace std;\r\n\r\n\/*\r\n  Push Items To Vector\r\n  {\"Osama\", \"Ahmed\", \"Sayed\", \"Ali\"} -> Size = 4\r\n*\/\r\n\r\nvector<string> pushItem(vector<string> v, string item)\r\n{\r\n  \/\/ Create Vector With One More Element\r\n  vector<string> result(v.size() + 1);\r\n\r\n  \/\/ Copy Elements From Main Vector To The New Vector\r\n  for (int i = 0; i < v.size(); i++)\r\n  {\r\n    result[i] = v[i];\r\n  }\r\n\r\n  \/\/ Add The Item\r\n  result[v.size()] = item;\r\n\r\n  return result;\r\n}\r\n\r\nint main()\r\n{\r\n  vector<string> names = {\"Osama\", \"Ahmed\", \"Sayed\", \"Ali\"};\r\n  names = pushItem(names, \"Mahmoud\");\r\n  names = pushItem(names, \"Gamal\");\r\n  for (string name : names)\r\n  {\r\n    cout << name << endl;\r\n  }\r\n  return 0;\r\n}\r\n<\/script>","protected":false},"excerpt":{"rendered":"<p>\u0645\u062d\u062a\u0648\u0649 \u0627\u0644\u062f\u0631\u0633<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1454],"tags":[],"class_list":["post-14747","post","type-post","status-publish","format-standard","hentry","category-implement-functions-with-cpp"],"_links":{"self":[{"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/posts\/14747","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/comments?post=14747"}],"version-history":[{"count":1,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/posts\/14747\/revisions"}],"predecessor-version":[{"id":14748,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/posts\/14747\/revisions\/14748"}],"wp:attachment":[{"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/media?parent=14747"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/categories?post=14747"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/tags?post=14747"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}