How do you find any fact about any state in one keystroke?
My very first C++ project: a lightweight, terminal-based search system that parses a 50-row CSV, indexes every field in memory, and serves O(log n) look-ups via binary search.
♡ What problem does it solve?
Centralises state facts.
No more scrolling through Wikipedia tables — query statehood year, capital, area or abbreviation from one prompt.Teaches core CS.
Hands-on practice with file-I/O, structs, vectors, sorting & searching algorithms.Runs everywhere.
Pure C++17, single executable, < 100 KB binary.
♡ Tech stack
Layer | Tools & Notes |
---|---|
Language | C++17 — modern features (auto, ranged-for, std::string_view) |
Data model | struct State { … } stored in a std::vector |
Indexing | Pre-sorted by key, binary search via std::lower_bound |
Parsing | std::ifstream + getline + std::stringstream |
Build | g++ -O2 search.cpp -o search (VS Code tasks.json) |
UX | Command-line prompts, coloured output with ANSI codes |
♡ Key features
Flexible queries — select any column (name, capital, region, year…)
and retrieve the row in under a millisecond.Optimised search — vector sorted at start-up; look-ups use std::binary_search() → O(log n).
Graceful fallback — invalid keys return suggestions
(Did you mean “MA” ?).Scalable design — swap the CSV to 5 000 rows with zero code changes;
RAM grows linearly.
♡ Sample session
$ ./search
➜ Enter query type [state | capital | abbr | year]: state
➜ Enter value: Michigan
──────────────────────────────────────────────
State: Michigan (MI)
Capital: Lansing
Statehood (year): 1837
Region: Midwest
Area (sq mi): 96 716
──────────────────────────────────────────────