[英]lexical_cast with negative number behaves differently on different machines
我在兩個不同的設備上具有相同版本的Boost,但是對於
lexical_cast<uint>("-1")
文檔指出它應該給我INT_MAX(2的補碼翻轉),但是在一台機器上我會拋出異常,而在另一台機器上我會得到INT_MAX。
顯然,如果您查看boost的lexical_cast
代碼,則會使用類似interpreter << arg; interpreter >> result
的代碼來加載和操作輸入interpreter << arg; interpreter >> result
interpreter << arg; interpreter >> result
和>>
運算符中
this->setg(start, start, finish);
std::basic_istream<CharT> stream(static_cast<Base*>(this));
stream.unsetf(std::ios::skipws);
它使用std::basic_istream
因此libstdc ++的不同版本將導致lexical_cast
在不同計算機上的行為不同。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.