Er is een C-stijl atoi
, maar converteert naar een int
. Je moet zelf naar char
casten.
Voor een oplossing in C ++ -stijl (die ook veiliger is) die u kunt doen
string input("128");
stringstream ss(str);
int num;
if((ss >> num).fail()) {
//invalid format or other error
}
char result = (char)num;