-1

Hello I am using c++ for this assignment.

If I have a string such as "P10" and I want to store the number 10 into an integer disregarding the P, how would I do that?

  • Does this answer your question? [how to extract a number from string in c++](https://stackoverflow.com/questions/32586048/how-to-extract-a-number-from-string-in-c) – rsjaffe May 04 '20 at 20:22
  • You'd read and parse the string. Extract the integer component you are interested in, convert it to an integer representation and store it in your variable. There's no magic, do what you'd do with pencil and paper - one character at a time. – Jesper Juhl May 04 '20 at 20:34

1 Answers1

1

Assuming you only want to remove the first character from your string then

#include <string>

std::string str = "P10";
int i = std::stoi(str.substr(1));
john
  • 72,145
  • 4
  • 50
  • 71