Get the last element of a std::string

后端 未结 4 1006
自闭症患者
自闭症患者 2020-12-08 03:38

I was wondering if there\'s an abbreviation or a more elegant way of getting the last character of a string like in:

char lastChar = myString.at( myString.le         


        
4条回答
  •  一生所求
    2020-12-08 04:07

    *(myString.end() - 1) maybe? That's not exactly elegant either.

    A python-esque myString.at(-1) would be asking too much of an already-bloated class.

提交回复
热议问题