std :: from_chars无法在MSVC下编译 [英] std::from_chars doens't compile under MSVC

查看:99
本文介绍了std :: from_chars无法在MSVC下编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个小函数,它使用 std :: from_chars std :: string_view ,虽然在ubuntu下使用clang或gcc进行编译,但在Windows下却不使用msvc。

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;
}

对于每个 std :: from_chars 调用时在编译时显示以下错误:

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


'std :: from_chars':这14个重载都不能转换所有参数类型

'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'

'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?

推荐答案

一些程序员伙计所述, Ruks std :: string_view.begin()不返回 const char * const std :: string_view.data()是我正在寻找的方法。

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.

这篇关于std :: from_chars无法在MSVC下编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆