In this example :
#include <iostream>
#include <vector>
#include <string>
typedef std::vector<std::string> vs;
vs test1()
{
vs strings;
strings.push_back("a");
strings.push_back("b");
strings.push_back("c");
return strings;
}
void test2(vs& strings)
{
strings.push_back("a");
strings.push_back("b");
strings.push_back("c");
}
int main()
{
vs data = test1();
test2(data);
return 0;
}
I test two ways to fill a vector of string. I presume that in first case we copy the vector, in the second case it's probably better because we just give the ref of the vector. So what is the good way, the copy is it a very big cost for the computer ?
thanks for you answer !