sting

std::string String[] = {...};
this string hold 50 elements when i have it run the program i have a variable access a curtain location.
int Word = String[iElementSelected];
I debug it and stop program to see what the value of things are. how come string is equal to the first element? say it was:
std::string String[] = { "the", "hi", ...};

int iElementSelected = 2;

String[iElementSelected];

when i debug it says the value of:
String = "the"
iElementSelected = 2
word = "hi"

so why does String equal "the"?
sorry for the long and probably unnecessary explanation.
If you want to see the second element then: String[0] == "the", String[1] == "hi" etc.
C arrays are really just pointers to the first element of the array. It is therefore normal to see that the value of the entire array is equal to the first element of the array.

if (String == &String[0]) cout << "It's true!";

The above code fragment is proof that String is equal to the address of the first element in the array.
Topic archived. No new replies allowed.