-1

Lets say I have a string variable with the value "bananas" in it. I want to subtract the last letter so the string becomes "banana". I am quite a newbie, so I dont even know how to tackle this.

  • 4
    [std::string::substr](https://en.cppreference.com/w/cpp/string/basic_string/substr) and [std::string::pop_back](https://en.cppreference.com/w/cpp/string/basic_string/pop_back) might be helpful – Nathan Pierson Jun 18 '22 at 03:55

1 Answers1

3

Just use the pop_back() function.

Try this code, it 'subtracts' the last character:

std::string str = "bananas";
str.pop_back();
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
Tommy Au
  • 86
  • 4