Converting vector of chars into vector of ints

Hi guys,im kinda new to c++,need your help a little bit
I have a string called "digits" which is used for operations with big integers,
i made a vector out of that string,but that vector is char vector,
and i need it to be a vector of integers so i can operate with it?
Anyone can help ?

string digits("432234123");
vector<char> v(digits.begin(), digits.end()); and now i need to convert it but duunno how,


Tnx in advance!
Last edited on
make it a vector of ints and subtract the value of '0' to get the numbers

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// Example program
#include <iostream>
using std::cout;

#include <string>
using std::string;

#include <vector>
using std::vector;

int main()
{
    string digits("432234123");
    vector<int> v(digits.begin(), digits.end());
    
    for(auto& i : v)
        i -= '0'; // make digits to numbers
    for(const auto& i : v)
        std::cout << i << '\n'; // print digits
}
Last edited on
tnx man u saved me :)
Topic archived. No new replies allowed.