I have this code and wondering if it's possible to have stringstream to treat uint8_t as a number not a character?
uint8_t s;
std::stringstream sstream( "255" );
sstream >> s;
std::cout << s << " equals 50/'2' not 255 " << std::endl;
s should be 255 not 50/'2'
If you are using std::stringstream in order to convert uint8_t to string, then you can use std::to_string instead. Allowed in c++11 only.
#include <stdint.h>
#include <iostream>
uint8_t value = 7;
std::cout << std::to_string(value) << std::endl;
// Output is "7"
Cast it to an int
:
std::cout << (int)s << " equals 2 not 255 " << std::endl;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With