I have this (incorrect) sample code to get a value from a string stream and store it in a variable byte size (it should be in one byte of var, not in int):
#include <iostream> #include <sstream> using namespace std; int main(int argc, char** argv) { stringstream ss( "1" ); unsigned char c; ss >> c; cout << (int) c << endl; }
The way out when I run this is 49, which is not what I would like to see. Obviously, this is considered a char, not a simple numeric value. What is the most C ++ ish way to force c to hold 1, not 49 when casting to int?
Thanks!
c ++ iostream stringstream
twk
source share