Programming foundations

Stage 6 · Lesson 3 of 7

Files and parsing input

Build and ship your first projects

A C++ usually reads a text file, such as a CSV of transactions, and turns each line into a struct (a small record type). uses std::ifstream and std::getline, and you split the fields with std::istringstream.

Convert text with std::stoi or std::stod, which std::invalid_argument on bad text. Catch that exception and report the line number, so users can fix their file. Decide what a bad line means: skip it with a warning, or stop.

Check that the stream opened, and remember that are worked out from where the program runs. Keep parsing in its own that returns a std::vector of structs, so the core logic and the tests never touch files.

A question to check yourself, an AI practice session and 2 cheat sheet entries come when you add the roadmap to your account. Add it

Resources for this stage

Start with

  • GitHub repoFree
    Project Based Learning

    Community maintained · Beginner

    Follow one guided build in your language, then build your own without a guide

Keep handy

  • Free APIs that give a small project real data to work with

Also worth your time

Mark this stage as not done?