这是生物信息学在Github上非常流行的C++项目:为什么这个Github项目将字符串转换为bool?
https://github.com/jts/sga/blob/master/src/Util/ClusterReader.cpp
有一行:
bool good = getline(*m_pReader, line);
我不能编译这条线上,我不不知道作者为什么这样做。
根据documentation,getline
返回一个字符串不bool。事实上,这是我在尝试编译该项目时得到的结果:
ClusterReader.cpp: In member function ‘bool
ClusterReader::readCluster(ClusterRecord&)’:
ClusterReader.cpp:70:41: error: cannot convert ‘std::basic_istream<char>’ to ‘bool’ in initialization
bool good = getline(*m_pReader, line);
为什么C++代码将字符串转换为bool?这怎么可能?
不,std :: getline返回原始流,如果没有错误,流上的布尔类型转换将返回“true”。你使用什么编译器?如果你想解决这个问题,你可以修改该行为'bool good = getline(* m_pReader,line).good();' – paddy
这表明编译器错误(包括编译器和库安装可能不匹配)。你使用的是什么编译器和设置? –