Difference between string.empty and string[0] == '\0'

前端 未结 6 1635
予麋鹿
予麋鹿 2021-02-11 12:15

Suppose we have a string

std::string str; // some value is assigned

What is the difference between str.empty() and str[0] =

6条回答
  •  醉梦人生
    2021-02-11 12:22

    empty() is not implemented as looking for the existence of a null character at position 0, its simply

    bool empty() const
    {
        return size() == 0 ;
    }
    

    Which could be different

提交回复
热议问题