2017-10-24 10 views
-2

내가 비주얼 스튜디오 2017에서 컴파일 Solipsis을 얻으려고 (그것은 VS 2005 작성되었습니다)istream 추출 연산자 >>는 무엇을 반환합니까?

이 코드가 시도되고 있는지 알 수 없습니다

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

[표준 : 이건 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와 비교하여 성공/실패 여부를 확인할 수있었습니다.

return iss >> Dest != 0; 

당신은 C++ (11) 컴파일과 (VS2017 말할) 그렇게 할 수 없으며, 그 이유는 제안 된 중복 질문에 훌륭한 대답에 제시되어있다 :

What does the istream extraction operator >> return?

오히려 부울로 캐스팅하여 함수를 현대화하십시오.

return bool(iss >> Dest);