integer extraction from string

前端 未结 5 962
天命终不由人
天命终不由人 2021-01-26 18:37

I have an input argument string const char* s I know that it starts the sequence of chars which are integers representation ,this sequence could be of any length ,

5条回答
  •  走了就别回头了
    2021-01-26 19:07

    Try atoi() or the complete strtol():

    int x = atoi("23meeting");
    int x = (int)strtol("23meeting", (char **)NULL, 10);
    

    Check the man pages on your system (section 3 in Unix).

提交回复
热议问题