How to parse a string to an int in C++?

前端 未结 17 2063
忘了有多久
忘了有多久 2020-11-21 11:01

What\'s the C++ way of parsing a string (given as char *) into an int? Robust and clear error handling is a plus (instead of returning zero).

17条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-21 11:45

    In C, you can use int atoi (const char * str),

    Parses the C-string str interpreting its content as an integral number, which is returned as a value of type int.

提交回复
热议问题