vector::data returns pointers to the elements of the vector. Therefore c should include those, however, I do not understand where those negative numbers come from.
Well why would you want to interate through arr which would appear to be a char[] (i.e. character array) and then read data from your vector? The cha[] i.e. arr appears to hold more data than your vector, you appear to be assuming that both are in sync which they cannot be.
You would either iterate through your vector:
1 2 3 4
for (auto p = v.begin(); p != v.end(); ++p)
{
cout << *p << endl;
}
Or iterate through your char[]:
1 2 3 4
for (int n = 0; n < strlen(c); ++n)
{
cout << c[n] << endl;
}
Don't iterate through one and read from the other.
If vector::data is just for null terminated strings, then how would you solve my assignment?
No, vector::data is not just for null-terminated strings.
strlen is just for null-terminated strings.
You're passing a character array into strlen, and it's returning a different value from the one you're expecting, because the character array is not null-terminated. So your loop is iterating a larger range than you expect it to, and is attempting to read characters after the end of the array.