I want to store the hex values into a string, but I don't know to do that when my string is not giving me the hex values when it is printed out. I'm pretty sure it has something to do with hex, but I don't know how to get those int values that print out the correct hex values to be stored into a string without it being changed.
I tried different ways of manipulating this and searched on the web but have not found much of a solution in solving this.
#include
#include
#include
#include
#include
#include
#include
using std::cout;
using std::endl;
using std::string;
using std::hex;
using std::stringstream;
using namespace std;
int main(){
string s2 = "HelloWorld";
cout << "string: " << s2 << endl;
cout << "hexval: ";
vector<int> character; // converting each character to its ascii value
string bytes;
for(int i = 0; i < s2.size(); i++) {
character.push_back(int(s2[i]));
bytes = to_string(character.at(i));
cout << hex << character.at(i) << " ";
cout << bytes << endl;
}
cout << endl;
cout << bytes << endl;
return 0;
}
Here is the output that 'bytes' my string is printing out:
48 72
65 101
6c 108
6c 108
6f 111
57 87
6f 111
72 114
6c 108
64 100
Left is the hexadecimals and right is the string. Two different values. How can I store these hexadecimals that is being converted from a string be stored into a string as a hexadecimal value?
JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)