Parapura's answer is correct, but you will be storing the pointers to the strings. If the original character array falls out of scope you will lose the information posted. If this vector is used elsewhere, it should allocate (and deallocate!) it's own memory. This can be done when the input is taken.
Here's a sample program that does that.
#include <vector>
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
using std::vector;
int main()
{
int numEntries = 4;
const int strlen = 40;
// Parapura's correct answer, but let's expand this further
vector<char*> strvec;
char* input = 0;
int i;
cout << "Enter four names." << endl;
for (i=0; i<numEntries; i++)
{
// Allocate some memory to store in the vector
input = new char[strlen];
cout << "Name: ";
cin.get(input, strlen);
cin.ignore(strlen, '\n');
// Push the populated memory into the vector.
// Now we can let 'input' fall out of scope.
strvec.push_back(input);
}
cout << endl;
/* -- cool code here! -- */
cout << "List of names." << endl;
for (i=0; i<numEntries; i++)
{
cout << strvec[i] << endl;
}
/* -- more cool code! -- */
// don't forget to clean up!
for (i=0; i<numEntries; i++)
{
delete[] strvec[i];
}
return 0;
}