I have a function which feeds a vector series of numbers. This series of numbers is to be appended to form a long long number and get stored in another vector.
Eg.
Vector1= |2|3|4|5|5|
vector2= |23455| |
A space indicates the end of one number and functions starts to output second number series. I think reverse iterator and multiply by 10^x
is somehow a solution.
Eg code
vector<long long> a, fin;
for (int i = 0; i <6; i++)
{
a.push_back(i + 1); // adds 1 2 3 4 5 6 in slots of v1
}
int j = 0;
for (vector<long long>::reverse_iterator i = a.rbegin(); i != a.rend(); i++) {
// want to append v1 members to form one number 123456 and store it in first slot of vector2;
fin[0] += (a[(*i)] * (10 ^ j));
j++;
}
cout << fin[0];
You didn't put any elements in your
fin
vector. Also you mistook^
for power function. You need to use std::pow:Try:
Output: