How to convert string to a vector with hex values in C++

1 Answer

0 votes
#include <iostream>
#include <sstream>
#include <vector>

int main()
{
    std::string c = "c++";
    
    std::vector <std::string> v;
    
    for (auto ch: c) {
        std::ostringstream oss;
        oss << std::hex << static_cast<int>(ch);
        v.push_back( oss.str() );
    }

    for (auto s: v)
        std::cout << s << " ";
    
    return 0;
}


  
/*
run:
  
63 2b 2b 
 
*/

 



answered Sep 20, 2021 by avibootz

Related questions

1 answer 215 views
1 answer 149 views
1 answer 140 views
1 answer 146 views
2 answers 111 views
1 answer 107 views
...