Dumping contents of a vector/list to cout

Is it possible to do this with just one line of code? Oh yes! Have a look… [sourcecode language=”cpp”]typedef int VT; typedef std::vector VTVec; void Dump( VTVec& VecToPrint, std::ostream& stream, const char* lpszMsg ) { // We will be wrapping every element within a square bracket. // In the end output looks like this… [123] […]
Continue reading…

 

Filling out a vector using generate function

Let us suppose that you want to fill out a vector with 10000 random elements, phew. Hmm so what you would do is to write a for loop, iterate through, and fill out the elements. Well I can do it with just one line of code. 🙂 Look [sourcecode language=”cpp”]// Typedefs typedef int VtElem; typedef […]
Continue reading…

 

Initializing vector elements to a particular value

There are 8 constructors for std::vector class, out of which there is this constructor that takes two parameters… [sourcecode language=”cpp”]vector( size_type _Count,  const Type& _Val );[/sourcecode] First parameter is size of the vector, second is default value for all elements in the vector. Let’s suppose you have 1000 Employees in your organization each of them has an initial […]
Continue reading…