Confused how to convert from a string to double using strtod() in C++

前端 未结 3 877
心在旅途
心在旅途 2021-01-14 11:08

If someone could explain how to use the function, that would be great. I don\'t understand the parameters.

Thanks

3条回答
  •  一向
    一向 (楼主)
    2021-01-14 11:39

    First parameter is a pointer to the chars. c_str() gives you that pointer from a string object. Second parameter is optional. It would contain a pointer to the next char after the numerical value in the string. See http://www.cplusplus.com/reference/clibrary/cstdlib/strtod/ for more infos.

    string s;
    double d;
    
    d = strtod(s.c_str(), NULL);
    

提交回复
热议问题