Quick Simple Parser

I tend to fall back on scanf when I have to parse simple text files. - Simple string parsing with C++

char line[SOME_SIZE];
while (fgets(line, SOME_SIZE, file)) {
    int x, y, z;
    if (3 == sscanf(line, "foo: [%d %d %d]", &x, &y, &z)) {
        continue;
    }
    float w;
    if (1 == sscanf(line, "baz: %f", &w)) {
        continue;
    }
}

see also:

Written on December 18, 2022, Last update on February 27, 2023
c++ config parser single-header json toml