Vector Dynamic Allocation

I am stuck in the following exercise:
Can i get some help please
Create a short program that:
- Declares a variable named p that can point to a vector of strings.
- Ask the user how big the vector should be, and what string to set all of its elements to. - Allocate that vector, and fill it with the requested values.
- Deallocate the memory pointed to by p.

Thanks in advance
closed account (o3hC5Di1)
Hi There,

Here's some reading material that may help you:

http://www.dreamincode.net/forums/topic/33631-c-vector-tutorial/
http://www.dreamincode.net/forums/topic/34015-c-vector-tutorial-ii/

All the best,

NwN
- Declares a variable named p that can point to a vector of strings.


std::vector<std::string> *p;

One third of your assignment has been done.:)
Last edited on
closed account (zb0S216C)
"Vector" is ambiguous. A vector can be either an array of something or a std::vector. Judging by the assignment, I'm assuming you mean an array of strings, namely:

 
const char *VectorOfStrings[] = {"...", "...", "..."};

The std::vector is the same internally as a normal array, but it's allocated in a different way from the basically allocated array.

Wazzak
Last edited on
Topic archived. No new replies allowed.