When running this example compiled with Visual Studio 2013, an "invalid argument" error is thrown.
在运行使用Visual Studio 2013编译的此示例时,会引发“参数无效”错误。
#include <iostream>
#include <string>
#include <stdexcept>
int main()
{
std::string inf = "inf";
try{
double dinf = std::stod(inf);
}
catch (const std::exception& e){
std::cout << e.what() << std::endl;
exit(1);
}
exit(0);
}
It's my understanding that VS2013 uses the C++11 standard, and cppreference std::stod is tagged with (since C++11)
and clearly lists (case-insensitive) INF
/INFINITY
as valid values.
据我所知,VS2013使用的是C++11标准,并且使用(从C++11开始的)标签和明确列出的(不区分大小写的)INF/infinity作为有效值。
I've confirmed that I can compile/run a program using std::numeric_limits<double>::infinity()
in VS2013.
我已经确认可以在VS2013中使用std::Numic_Limits
::Infinity()编译/运行程序。
So, my question is this: what's the deal? Does VS2013 only support part of the C++11 standard? How can one tell what's supported and what isn't? Multiple google searches have yielded exactly nil when it comes to C++ documentation specifically for VS2013.
所以,我的问题是:这是怎么回事?VS2013是否只支持部分C++11标准?怎么知道什么是受支持的,什么不是呢?当涉及到专门针对VS2013的C++文档时,多次谷歌搜索都没有得到任何结果。
BTW I would love for the solution to be "use any newer version of VS because Visual Studio 2013 is garbage", but alas I am constrained on this front.
顺便说一句,我希望解决方案是“使用任何更新版本的VS,因为Visual Studio2013是垃圾”,但遗憾的是,我在这方面受到限制。
更多回答
What "solution" you want? Even it is a bug, nobody will be fixing it in 10 years old and 5 releases back product.
你想要什么“解决方案”?即使它是一个错误,也没有人会在10年后修复它,并发布5个Back产品。
Here this issue is listed as fixed in VS 2015: The stod() family mishandled INF/NAN inputs by throwing exceptions (DevDiv#1113936/Connect#1098595). We’re now following the Standards exactly.
在VS2015中,这个问题被列为已修复:stod()家族通过抛出异常错误地处理了INF/NaN输入(DevDiv#1113936/Connect#1098595)。我们现在完全遵循标准。
Does VS2013 only support part of the C++11 standard? — why of course yes. The dramatic emphasis is unwarranted. Every compiler deviates from the standard.
VS2013只支持C++11标准的一部分吗?-当然支持。这种戏剧性的强调是没有根据的。每个编译器都偏离了标准。
@500-InternalServerError thank you for the link, that table is enlightening :)
@500-InternalServerError感谢您的链接,该表具有启发性:)
优秀答案推荐
Special thanks to a couple of the commenters, going to repost here as a "solution" for future reference.
特别感谢几位评论者,他们将在这里转发,作为未来参考的“解决方案”。
I did not know it was a known bug; I'm glad to know I wasn't going crazy and it's actually a known bug. For some reason or another did not find this page while trying a silly amount of different search queries for this issue, so thank you a bunch to @dewaffled for the reference!
我不知道这是一个已知的错误;我很高兴知道我没有发疯,它实际上是一个已知的错误。由于这样或那样的原因,在为这个问题尝试了大量不同的搜索查询时,没有找到这个页面,所以非常感谢@dewaffleed的参考!
Here this issue is listed as fixed in VS 2015: The stod() family mishandled INF/NAN inputs by throwing exceptions (DevDiv#1113936/Connect#1098595). We’re now following the Standards exactly. -- dewaffled
Also, I found this table to be quite informative, so thank you as well :)
另外,我发现这张表的信息量很大,所以我也要谢谢你:)
Does VS2013 only support part of the c++11 standard?
- correct. Here's an old table with some details -- 500 - Internal Server Error
更多回答
Hi, glad to know your problem has been solved! Please consider accepting it to change its status to Answered.
嗨,很高兴知道你的问题已经解决了!请考虑接受它以将其状态更改为已应答。
我是一名优秀的程序员,十分优秀!