std::from_chars doens't compile under MSVC

江枫思渺然 提交于 2020-08-06 05:07:22

问题


I have a little function that uses std::from_chars to create a date object from a std::string_view, while it compiles using clang or gcc under ubuntu it doesn't using msvc under windows.

date::year_month_day parseDate(const std::string_view& s)
{
    int y { 0 }, m { 0 }, d { 0 };

    std::from_chars(s.begin(), s.begin() + 4, y);
    std::from_chars(s.begin() + 5, s.begin() + 7, m);
    std::from_chars(s.begin() + 8, s.begin() + 10, d);

    return date::year { y } / m / d;
}

For each of std::from_chars call the following error is displayed at compile time:

'std::from_chars': none of the 14 overloads could convert all the argument types

The compiler then proceeds to make a list of possible overloads and i clearly see the one that I'm trying to use:

'std::from_chars_result std::from_chars(const char *const ,const char *const ,int &,const int) noexcept'

The last parameter has a default value. Can someone explain me what I'm doing wrong?


回答1:


As mentioned by Some programmer dude and Ruks, std::string_view.begin() doesn't return a const char *const, std::string_view.data() was the method i was looking for.



来源:https://stackoverflow.com/questions/61203317/stdfrom-chars-doenst-compile-under-msvc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!