I am trying to make a copy of a row vector and add it to the end of my original vector, i.e. duplicating its contents. Example:
Input : vector<string> s = {"abc", "def"}
Output: vector<string> s = {"abc", "def", "abc", "def"}
I used the insert method, i.e.
s.insert(s.end(), s.begin(), s.end());
However, this shows compiler-specific results. In, LLVM clang, he gave me the expected answer.
With gcc he gave me
Output: vector<string> s = {"abc", "def", "", ""}
I wonder why this happens and what is the safest way to achieve this vector duplication goal?
Here is the ideone.com link for the program above: http://ideone.com/40CH8q
source
share