C++ most efficient way to convert string to int (faster than atoi)

后端 未结 10 970
遥遥无期
遥遥无期 2020-12-04 17:04

As mentioned in the title, I\'m looking for something that can give me more performance than atoi. Presently, the fastest way I know is

atoi(mystring.c_str(         


        
10条回答
  •  长情又很酷
    2020-12-04 17:25

    Why not use a stringstream? I'm not sure of its particular overhead, but you could define:

    int myInt; 
    string myString = "1561";
    stringstream ss;
    ss(myString);
    ss >> myInt;
    

    Of course, you'd need to

    #include  
    

提交回复
热议问题