#mastery<\/a>23 #TC<\/a>1017 Creation and use of vectors in C++<\/span><\/p>\n Vector<\/em>\u00a0is a template class that is a perfect replacement for the good old C-style arrays. It allows the same natural syntax that is used with plain arrays but offers a series of services that free the\u00a0<\/span>C++ programmer<\/strong>\u00a0from taking care of the allocated memory and help operating consistently on the contained objects.<\/span>The first step using<\/span>\u00a0<\/span>vector<\/em>\u00a0<\/span>is to include the appropriate header:<\/span><\/p>\n Note that the header file name does not have any extension; this is true for all of the Standard Library header files. The second thing to know is that all of the Standard Library lives in the namespace\u00a0std<\/em>. This means that you have to resolve the names by prepending\u00a0std::<\/em>\u00a0to them:<\/p>\n For small projects, you can bring the entire namespace\u00a0std<\/em>\u00a0into scope by inserting a using directive on top of your\u00a0cpp<\/strong>\u00a0file:<\/p>\n This is okay for small projects, as long as you write the using directive in your cpp file. Never write a using directive into a header file! This would bloat the entire namespace\u00a0std<\/em>\u00a0into each and every cpp file that includes that header. For larger projects, it is better to explicitly qualify every name accordingly. I am not a fan of such shortcuts. In this article, I will qualify each name accordingly. I will introduce some\u00a0typedef<\/em>s in the examples where appropriate\u2014for better readability.<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":" #mastery<\/a>23 #TC<\/a>1017 Creation and use of vectors in C++<\/span><\/p>\n Vector<\/em> is a template class that is a perfect replacement for the good old C-style arrays. It allows the same natural syntax that is used with plain arrays but offers a series of services that free the <\/span>C++ programmer<\/strong> from taking care of the allocated memory and help operating consistently on the contained objects.<\/span>The first step using<\/span> <\/span>vector<\/em> <\/span>is to include the appropriate header:<\/span><\/p>\n Note that the header file name does not have any extension; this is true for all of the Standard Library header files. The second thing to know is that all of the Standard Library lives in the namespace std<\/em>. This means that you have to resolve the names by prepending std::<\/em> to them:<\/p>\n For small projects, you can bring the entire namespace std<\/em> into scope by inserting a using directive on top of your cpp<\/strong> file:<\/p>\n
<\/span><\/p>\n\n
\n
\n
<\/span><\/p>\n\n
\n