If I want to get the Cartesian Product of these two vector
s:
vector final{\"a\",\"b\",\"c\"};
vector temp{
You may try the following approach
#include
#include
#include
int main()
{
std::vector final{ "a", "b", "c" };
std::vector temp{ "1", "2" };
auto n = final.size();
final.resize( final.size() * temp.size() );
for ( auto i = n, j = final.size(); i != 0; --i )
{
for ( auto it = temp.rbegin(); it != temp.rend(); ++it )
{
final[--j] = final[i-1] + *it;
}
}
for ( const auto &s : final ) std::cout << s << ' ';
std::cout << std::endl;
return 0;
}
The program output is
a1 a2 b1 b2 c1 c2