-4

How can I parse numbers 4648, 4649, 4650 from this string into three int variables without using regex.h?

* SEARCH 4648 4649 4650
a3 OK SEARCH completed
John Doe
  • 1
  • 2

1 Answers1

0

Try using std::istringstream:

static const std:string    test_string = "* SEARCH 4648 4649 4650";
char asterisk;
std::string label;
unsigned int value1, value2, value3;
std::istringstream input(test_string);
input >> asterisk >> label >> value1 >> value2;

Edit 1:
For inputing more than one number:

input >> asterisk >> label;
std::vector<unsigned int> numbers;
unsigned int value;
while (input >> value)
{
  numbers.push_back(value);
}
Thomas Matthews
  • 56,849
  • 17
  • 98
  • 154