Skip to content

ryangraham/csv

Repository files navigation

Build Status GitHub license

CSV

A C++ header-only CSV parser with an interface inspired by Python's DictReader/DictWriter.

Table of Contents

Installation

Install csv using Homebrew.

brew tap ryangraham/csv
brew install csv

Usage

  std::string input_file_name = "../input.csv";
  std::fstream ifs(input_file_name);

  if (!ifs) return 1;

  auto reader = csv::map_reader(ifs);

  std::cout << reader.field_names.front() << std::endl;
  std::cout << std::string(10, '-') << std::endl;

  for (auto& row : reader.rows()) {
    std::cout << row["FirstName"] << std::endl;
  }

Will output something like...

FirstName
----------
Fred
Pebbles
Barney
Betty

Examples

See examples.