Want my function to move string from one array to another

Feb 20, 2014 at 9:58am
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
Feb 20, 2014 at 10:17am
use std::vector<std::string> 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 std::move if you have a C++11 capable toolchain
Feb 20, 2014 at 10:53am
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
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
There's already something for that in C++.
std::set.
Topic archived. No new replies allowed.