C++ character ASCII value to string -
very basic question. having problems in converting char char* points actual character. googling yielded information on strcpy, string, sprintf, etc. after many, many attempts @ trying understand problem, still can't work.
i have character array recv_msg contains ascii values of characters need. need store characters (not values) in vector msg.
what have:
std::vector<char> msg; char recv_msg[max_buffer_length]; ... int i; (i=0;i<bytes_transferred;i++) { msg.push_back(recv_msg[i]); } // problem: when process msg see 49 instead of '1'. if following sanity check, behavior need. is, see '5' , not 53 (ascii code 5).
std::vector<char*> msg; ... int i; char *val; (i=0;i<bytes_transferred;i++) { msg.push_back(val); } // no problem: when process msg see '5' instead of 53. so need turn ascii code values (char) character representation (char *). how on earth do this?
i want solve problem @ stage, , not have ascii -> character conversion when processing message.
based on
"i need store characters (not values) in vector msg"
try following, btw ascii 53 '5' only, may recv_msg stores ascii value only.
std::vector<char> msg; char recv_msg[max_buffer_length]; ... int i; (i=0;i<bytes_transferred;i++) { msg.push_back(recv_msg[i] - '0'); //subtract 48 numerals, }
Comments
Post a Comment