質問

I am writing a code in which I need to parse a string to a "long long int"

I used to use atoi when changing from string to int, I dont think it still work. What Can I use now?

--Thanks

役に立ちましたか?

解決

Use strtoll() (man page):

#include <stdlib.h>

long long int n = strtoll(s, NULL, 0);

(This is only available in C99 and C11, not in C89.) The third argument is the number base for the conversion, and 0 means "automatic", i.e. decimal, octal or hexadecimal are selected depending on the usual conventions (10, 010, 0x10). Just be mindful of that in case your string starts with 0.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top