Quick Simple Parser (scanf)
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:
- Parsing Command Line Arguments in C++?
- toml++ - TOML (.ini) config parser and serializer for c++
- json.hpp - Json for modern c++ - single-header
- mini-yaml - Single header YAML 1.0 C++11 serializer/deserializer.
Written on December 18, 2022, Last update on June 23, 2024
c++
config
parser
single-header
json
toml