Converting from a std::string to bool

前端 未结 14 2677
走了就别回头了
走了就别回头了 2020-12-25 09:51

What is the best way to convert a std::string to bool? I am calling a function that returns either \"0\" or \"1\", and I need a clean solution for turning this into a boole

14条回答
  •  青春惊慌失措
    2020-12-25 10:23

    It'll probably be overkill for you, but I'd use boost::lexical_cast

    boost::lexical_cast("1") // returns true
    boost::lexical_cast("0") // returns false
    

提交回复
热议问题