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

前端 未结 7 2222
迷失自我
迷失自我 2021-02-11 11:43

Suppose we have a string

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

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

7条回答
  •  无人及你
    2021-02-11 12:32

    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

提交回复
热议问题