need help to understand in Arrays

I am doing a lesson in C++ and i am in a part where we are working with arrays. I am reading the book, but it is not really standing out to me what i am needing to learn with my project. If someone can take a minute (if you don not mind) and see if you can help me understand.
I need to have a array of 3 people john , sam , bob
in the program i will enter the employee number (john 1, sam 2,bob 3)
so i will enter the employee number, and when the program does all it needs to do , it will display the name that is affiliated with that number.
I am having some major issues understanding what is going on, and the book is not pointing it out very well. Can anyuone offer insight of what i am trying to do..

thanks in advance
(please note i did not put the whole problem cause i am not trying to get anyone to do it for me, i am just needing help to understand this better )

int arr[8]; This creates an array of 8 int elements. You can access the elements by using an index 0-7. arr[0] gives you the first element, arr[1] the second element etc. Note that arr[7] is the eight and last element in the array. You can replace int with whatever type you want to store in the array. In your case it sounds like you want to store strings.
Thank you for the response Peter, I have somewhat of an understnding of what you are telling me, is there a formal name to this array, or what this is called, like a pointer, or array to pointer or ecetera. The chapter i am on is supposed to explain what you are explaining, but you can see it is not doing a good job.
string array? There are many ways to handle strings. If you use const char* the array will look something like const char* arr[3]; if you use std:.string it will be std:.string arr[3]; To initialize the array elements you can just assign like this
1
2
3
arr[0] = "john";
arr[1] = "sam";
arr[2] = "bob";

or you can list them when you create the array
std::string arr[3] = {"john", "sam", "bob"};
Both ways should work independently of you using std::string or const char*.
Last edited on
Topic archived. No new replies allowed.