c++ std::string to boolean

前端 未结 5 890
天命终不由人
天命终不由人 2021-01-01 13:16

I am currently reading from an ini file with a key/value pair. i.e.

isValid = true

When get the key/value pair I need to convert a string

5条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-01 14:13

    If you can't use boost, try strcasecmp:

    #include 
    
    std::string value = "TrUe";
    
    bool isTrue = (strcasecmp("true",value.c_str()) == 0);
    

提交回复
热议问题