Convert char to int in C and C++

前端 未结 12 2136
梦毁少年i
梦毁少年i 2020-11-22 02:41

How do I convert a char to an int in C and C++?

12条回答
  •  北荒
    北荒 (楼主)
    2020-11-22 03:12

    int charToint(char a){
    char *p = &a;
    int k = atoi(p);
    return k;
    }
    

    You can use this atoi method for converting char to int. For more information, you can refer to this http://www.cplusplus.com/reference/cstdlib/atoi/ , http://www.cplusplus.com/reference/string/stoi/.

提交回复
热议问题