Feb 20, 2014 at 9:58am UTC
I have some function:
int doSomething(string o, int n)
but I want to copy elements in array o into another array. How can I do this given that o is of variable size?
To be more specific, my goal is to remove duplicate elements in an array. So, I could check if o[i] == o[i+1] and if so, o[i+1] would not be moved into the second array.
Last edited on
Feb 20, 2014 at 10:03am UTC
Feb 20, 2014 at 10:17am UTC
instead of string array if you can. Then you will know the total number of elements, find out duplicates and move them out. For moving can use
if you have a C++11 capable toolchain
Feb 20, 2014 at 10:53am UTC
String arrays don't always work, try a vector as codewalker suggested or maybe a linked list if you have an older compiler.
Feb 21, 2014 at 3:33pm UTC
Starting more than one thread on essentially same question is rude.
Deleting original question from the thread is rude.
You can perform the desired operation inplace in the array without additional containers.
std::string has copy assignment operator.
Your input array o has fixed size; not variable.
Feb 21, 2014 at 3:45pm UTC
There's already something for that in C++.