I have two vectors
typedef std::vector<std::string> messages;
typedef std::vector<std::string> addMessage;
messages st;
addMessage additionlMsgs;
when the user inputs a string i then split that string by a certain character which is then splitted into st
i want to copy that vector over to additionalMsgs at some point but i get a run time error i cannot see why.
i try to copy it over as follows
copy(st.begin(), st.end(), additionlMsgs.begin());
can you see anything that is incorrect?
Thanks
Shamari
It sounds like you’re looking for
std::back_inserter:That’ll append to
additionlMsgs. If you wish to overwrite its contents, you might want to use:The code you have right now never adds new elements to
additionlMsgs; it simply overwrites existing ones without performing any bounds checking. IfadditionlMsgsis too short, you get undefined behaviour.