This question is asked already, but I still am not able to fix it. Its an simple excercise from my studybook to copy an array into a vector. I read in the studybook that C-strings always ends with a zero character. According to my study book you can just solve this by adding -1 to the member function .end() when using it in a For loop. However when I execute it, I still get weird symbols showing up at the last element of the vector and the execute window will also crash. What am I doing wrong?
You are not using C-strings but std::strings, so there is no need to add -1.
What weird symbols do you get?
When I run the code you posted the output is: monkey-lion-
To get all 3 names you can do it like this:
Even if I remove the -1, I still get the weird symbols. Too bad I can't copy-past in the execute window but it looks roughly like this:
Monkey-lion- |É É É É É ■ É ■ É É É (the rest of the symbols are to difficult to find)
Perhaps its my compiler, because the correct code provided in my book also has the same problem. (and its also using the end()-1. I am using Code :: Blocks v13.12
Facepalm moment :/
Books code are fine, I edited the orginal code to not return a value, while forgetting to change the function into void. Thanks for all the advice.