提升:如何将像"true"或"1"这样的字符串转换为bool true,将"0"或"false"转换为bool false?

Rel*_*lla 3 c++ string boost boolean

boost::lexical_cast<bool, std::string>( string );唯一的选择还是有更快的方法做这样的事情,将它放在工作的True字符串,其无线本地环路上工作1的字符串,将它放在工作的TRUE字符串?

(因为对我来说它给出了bad lexical cast: source type value could not be interpreted as target错误)

Mar*_*som 5

一种快速的方法是map<string,bool>使用所有可接受的字符串及其布尔等价物进行预初始化.然后这只是一件事find.