I am trying to convert a vector of int to an int. This is how I proceed:
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
uint32_t toInt(vector<int> v)
{
uint32_t x=0;
for(int i=0 ; i<v.size() ; i++)
x+=v[i]*pow(10, v.size()-1-i);
return x;
}
int main()
{
vector<int> v = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
cout << toInt(v) << endl; // displays: 123456787 (???)
}
The program should output 123456789, but instead I have 12345678(!)7(!).
I am using GCC (tdm-1) 4.7.1 on Code::Blocks 13.12
Does someone have an explanation to this problem, and a way to solve it ? Thank you.