2017-10-24 14 views
-2

私はこのコードがやろうとしているかを把握することはできませんistream抽出演算子>>は何を返しますか?

(それはVS 2005のために書かれた)Solipsisは、Visual Studio 2017でコンパイルするために取得しようとしている:

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 Studio\2017\Community\VC\Tools\MSVC\14.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 Studio\2017\Community\VC\Tools\MSVC\14.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 Studio\2017\Community\VC\Tools\MSVC\14.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 Studio\2017\Community\VC\Tools\MSVC\14.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 Studio\2017\Community\VC\Tools\MSVC\14.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 Studio\2017\Community\VC\Tools\MSVC\14.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 Studio\2017\Community\VC\Tools\MSVC\14.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 

人間言語では、「>>」演算子の戻り値は何ですか(ビットシフトではなく抽出として使用される場合)?コードスニペットが機能しないVS 2005以降に変更されたことは何ですか?

+2

[STD :: basic_istream ::演算子>>](http://en.cppreference.com/w/cpp/io/basic_istream/operator_gtgt) –

+0

あなたは何演算子>>リターンを求めてか、されています関数が何をしているのか尋ねる? –

+0

[よくある質問](https://stackoverflow.com/help/how-to-ask)を参照してください。質問の名前を変更することをお勧めします。 – viddik13

答えて

0

私はこのコードがやろうとしているかを把握することはできません。

コードは、ストリーム抽出が成功したかどうかを返すようにしようとしています。

istream抽出演算子は何を返しますか?

オペレータの戻り値の型がコンパイルを壊しているのではなく、C++ 11以降の動作が変更されているためです。

C++ 11より前(VS2005と言う)には、istreamオブジェクトをtrue/falseと比較することで、成功/失敗を確認できました。

あなたがC++ 11のコンパイル(VS2017と言う)であることを行うことができない、との理由が示唆され、重複する質問への優れた答えに記載されている
return iss >> Dest != 0; 

What does the istream extraction operator >> return?

むしろブール値にキャストして関数を近代化してください。

return bool(iss >> Dest); 
関連する問題