There is a format string "123,456,123,23,789,67" . 6 numbers separated by commas. It is necessary to get the last 2 numbers into variables of type int .
The problem is solved easily with sscanf() :
#include <stdio.h> int main(int argc, char* argv[]) { char buf[] = "123,456,123,23,789,67"; int a1, a2, a3, a4, a5, p1, p2; sscanf(buf, "%d,%d,%d,%d,%d,%d", &a1, &a2, &a3, &a4, &p1, &p2); return 0; } Question: How to solve this problem using iterators and string class methods?