istream 提取运算符 >> return 是什么意思?

What does the istream extraction operator >> return?

我正在尝试让 Solipsis 在 Visual Studio 2017 年编译(它是为 VS 2005 编写的)

我不知道这段代码试图做什么:

template<typename T> 
bool from_string( const char* Str, T & Dest )
{
    // créer un flux à partir de la chaîne donnée
    std::istringstream iss( Str );
    // tenter la conversion vers Dest
    return iss >> Dest != 0;
}

出现以下错误

1>c:\users\root\source\repos\solipsis3d\sources\modelers\mdlrtools\include\SolipsisErrorHandler.h(91): error C2678: binary '!=': no operator found which takes a left-hand operand of type 'std::basic_istream<char,std::char_traits<char>>' (or there is no acceptable conversion)
1>C:\Program Files (x86)\Microsoft Visual Studio17\Community\VC\Tools\MSVC.11.25503\include\exception(347): note: could be 'bool std::operator !=(const std::exception_ptr &,const std::exception_ptr &) throw()' [found using argument-dependent lookup]
1>C:\Program Files (x86)\Microsoft Visual Studio17\Community\VC\Tools\MSVC.11.25503\include\exception(352): note: or       'bool std::operator !=(std::nullptr_t,const std::exception_ptr &) throw()' [found using argument-dependent lookup]
1>C:\Program Files (x86)\Microsoft Visual Studio17\Community\VC\Tools\MSVC.11.25503\include\exception(357): note: or       'bool std::operator !=(const std::exception_ptr &,std::nullptr_t) throw()' [found using argument-dependent lookup]
1>C:\Program Files (x86)\Microsoft Visual Studio17\Community\VC\Tools\MSVC.11.25503\include\system_error(379): note: or       'bool std::operator !=(const std::error_code &,const std::error_code &) noexcept' [found using argument-dependent lookup]
1>C:\Program Files (x86)\Microsoft Visual Studio17\Community\VC\Tools\MSVC.11.25503\include\system_error(384): note: or       'bool std::operator !=(const std::error_code &,const std::error_condition &) noexcept' [found using argument-dependent lookup]
1>C:\Program Files (x86)\Microsoft Visual Studio17\Community\VC\Tools\MSVC.11.25503\include\system_error(389): note: or       'bool std::operator !=(const std::error_condition &,const std::error_code &) noexcept' [found using argument-dependent lookup]
1>C:\Program Files (x86)\Microsoft Visual Studio17\Community\VC\Tools\MSVC.11.25503\include\system_error(394): note: or       'bool std::operator !=(const std::error_condition &,const std::error_condition &) noexcept' [found using argument-dependent lookup]
1>c:\users\root\source\repos\solipsis3d\sources\modelers\mdlrtools\include\SolipsisErrorHandler.h(91): note: or       'built-in C++ operator!=(bool, int)'
1>c:\users\root\source\repos\solipsis3d\sources\modelers\mdlrtools\include\SolipsisErrorHandler.h(91): note: while trying to match the argument list '(std::basic_istream<char,std::char_traits<char>>, int)'
1>src\Object3D.cpp(220): note: see reference to function template instantiation 'bool Solipsis::from_string<bool>(const char *,T &)' being compiled
1>        with
1>        [
1>            T=bool
1>        ]
1>c:\users\root\source\repos\solipsis3d\sources\modelers\mdlrtools\include\SolipsisErrorHandler.h(91): error C2446: '!=': no conversion from 'int' to 'std::basic_istream<char,std::char_traits<char>>'
1>c:\users\root\source\repos\solipsis3d\sources\modelers\mdlrtools\include\SolipsisErrorHandler.h(91): note: Constructor for class 'std::basic_istream<char,std::char_traits<char>>' is declared 'explicit'
1>SolipsisErrorHandler.cpp

在人类语言中,“>>”运算符的 return 值是多少(当用于提取而不是移位时)?自 VS 2005 以来,它发生了什么变化导致代码片段无法正常工作?

I can't figure out what this code is trying to do:

代码正在尝试 return 流提取是否成功。

What does the istream extraction operator >> return?

并不是 return 类型的运算符破坏了您的编译,而是因为自 C++11 以来行为发生了变化。

在 C++11(例如 VS2005)之前,您可以通过将 istream 对象与 true/false 进行比较来检查 success/failure。

return iss >> Dest != 0;

你不能用 C++11 编译(比如用 VS2017)做到这一点,原因在对建议的重复问题的出色回答中给出:

而是通过转换为布尔值来使您的函数现代化。

return bool(iss >> Dest);