Search System

Building a C++ × STL × CLI engine for instant look-ups on all 50 U.S. states

Algorithms
Command-Line
Author

Raameen Ahmed

Published

December 10, 2024

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

  1. Flexible queries — select any column (name, capital, region, year…)
    and retrieve the row in under a millisecond.

  2. Optimised search — vector sorted at start-up; look-ups use std::binary_search()O(log n).

  3. Graceful fallback — invalid keys return suggestions
    (Did you mean “MA” ?).

  4. 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
──────────────────────────────────────────────

♡ Code & data