M
Markus Ilmola
How to a parse a string using C++ (standard library) same way as sscanf
in C.
For example if a have a string:
My name is "John Smith" and I'm 13 years old and 120 cm tall.
and a want to parse the name (string that can be empty (whitout the
quotation marks)), age (unsigned int) and height (unsigned int).
Using plain C I could write something like this:
char name[64];
unsigned int age, height;
sscanf(buffer, "My name is \"%[^\"]\" and I'm %u years old and %u cm
tall.");
However I want to use C++ (standard library) and I need to read the name
to a std::string (buffer is also std::string).
in C.
For example if a have a string:
My name is "John Smith" and I'm 13 years old and 120 cm tall.
and a want to parse the name (string that can be empty (whitout the
quotation marks)), age (unsigned int) and height (unsigned int).
Using plain C I could write something like this:
char name[64];
unsigned int age, height;
sscanf(buffer, "My name is \"%[^\"]\" and I'm %u years old and %u cm
tall.");
However I want to use C++ (standard library) and I need to read the name
to a std::string (buffer is also std::string).