作者:书苑幽香 | 来源:互联网 | 2023-08-20 10:01
ThefollowingcodethrowsanexceptionwhenitisrununderVisualStudio2013butnotgcc4.9.2.以下
The following code throws an exception when it is run under Visual Studio 2013 but not gcc 4.9.2.
以下代码在Visual Studio 2013下运行但不是gcc 4.9.2时抛出异常。
The error reported is:
报告的错误是:
'exception: stol argument out of range'
'例外:stol争论超出范围'
stol
returns a long
so the size of temp
should be big enough to hold the returned value.
stol返回一个long,因此temp的大小应足够大以容纳返回的值。
Can anyone explain the behaviour. Is this possibly a compiler bug?
谁能解释这种行为。这可能是编译器错误吗?
#include
#include
#include
#include
int main()
{
const std::string value = "4294967295"; // 0xffffffff
try
{
int64_t temp = std::stol(value);
}
catch (std::invalid_argument& ex)
{
std::cout <<"invalid_argument: " <
5 个解决方案