문제

I'm using Visual C++ 2008. I can't use pop_back because it became a member function of the string class in C++11.

What could I use instead since I can't use pop_back?

도움이 되었습니까?

해결책

You can use std::string::erase, which I personally find a little more clear semantically than the resize alternative:

if (!s.empty())
  s.erase (s.size()-1);

다른 팁

You can use std::string::resize:

if (!s.empty())
  s.resize(s.size()-1);

I didn't quite understand your question but if you want to append something to a std::string you can use

std::string::append

and if you want to "shrink" it you can use

std::string::resize

There are at least two possibilites. Either to use member function erase or member function resize. for example

s.erase( s.size() - 1 );

or

s.resize( s.size() - 1 );

If you do not want to use push_back then you can substitute it for operator + or member function append.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top