vendredi 6 juillet 2018

How to construct integer value from vector

#include <iostream>
#include <vector>

int main()
{
    std::vector<bool> bitvec{true, false, true, false, true};
    std::string str;
    for(size_t i = 0; i < bitvec.size(); ++i)
    {   
        // str += bitvec[i];
        std::vector<bool>::reference ref = bitvec[i];
        // str += ref;
        std::cout << "bitvec[" << i << "] : " << bitvec[i] << '\n';
        std::cout << "str[" << i << "] : " << str[i] << '\n';
    }   
    std::cout << "str : " << str << '\n';
}

How we can construct an integer value from the std::vector of bool values. I thought to convert it to a std::string and then to integer from std::vector of bool values, but converting it to string from std::vector of bool values is failing. I know that both std::vector of bool and std::string elements are not the same type. So need help for the same.

Aucun commentaire:

Enregistrer un commentaire