{"id":13730400,"url":"https://github.com/awdeorio/csvstream","last_synced_at":"2026-01-16T14:10:59.503Z","repository":{"id":47156617,"uuid":"61372382","full_name":"awdeorio/csvstream","owner":"awdeorio","description":"An easy-to-use CSV file parser for C++","archived":false,"fork":false,"pushed_at":"2024-11-07T20:34:32.000Z","size":141,"stargazers_count":50,"open_issues_count":4,"forks_count":20,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-05-08T03:35:31.797Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/awdeorio.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-06-17T12:34:49.000Z","updated_at":"2025-04-21T21:30:15.000Z","dependencies_parsed_at":"2024-05-01T00:32:04.452Z","dependency_job_id":"91e0aee7-b143-4f5c-9705-64dd9581e5b8","html_url":"https://github.com/awdeorio/csvstream","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/awdeorio/csvstream","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/awdeorio%2Fcsvstream","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/awdeorio%2Fcsvstream/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/awdeorio%2Fcsvstream/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/awdeorio%2Fcsvstream/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/awdeorio","download_url":"https://codeload.github.com/awdeorio/csvstream/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/awdeorio%2Fcsvstream/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28479170,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-16T11:59:17.896Z","status":"ssl_error","status_checked_at":"2026-01-16T11:55:55.838Z","response_time":107,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-03T02:01:14.330Z","updated_at":"2026-01-16T14:10:59.486Z","avatar_url":"https://github.com/awdeorio.png","language":"C++","readme":"csvstream\n=========\n[![Build Status](https://travis-ci.com/awdeorio/csvstream.svg?branch=master)](https://travis-ci.com/awdeorio/csvstream)\n\nAn easy-to-use CSV file parser for C++\n\nAndrew DeOrio \u003cawdeorio@umich.edu\u003e\u003cbr\u003e\nhttp://andrewdeorio.com\n\n**Table of Contents**\n- [Quick start](#quick-start)\n- [Example 1: Read one column](#example-1-read-one-column)\n- [Example 2: Read each row and each column with nested loops](#example-2-read-each-row-and-each-column-with-nested-loops)\n- [Example 3: Maintaining order of columns in each row](#example-3-maintaining-order-of-columns-in-each-row)\n- [Changing the delimiter](#changing-the-delimiter)\n- [Allow too many or too few values in a row](#allow-too-many-or-too-few-values-in-a-row)\n- [Error handling](#error-handling)\n\n\n## Quick start\n```console\n$ git clone https://github.com/awdeorio/csvstream.git\n$ cd csvstream/\n$ make test\n```\n\n## Example 1: Read one column\nThis example reads one column from a CSV file.\n\n```c++\n// example1.cpp\n#include \"csvstream.hpp\"\n#include \u003ciostream\u003e\n#include \u003cstring\u003e\n#include \u003cmap\u003e\nusing namespace std;\n\n\nint main() {\n  // Open file\n  csvstream csvin(\"input.csv\");\n\n  // Rows have key = column name, value = cell datum\n  map\u003cstring, string\u003e row;\n\n  // Extract the \"animal\" column\n  while (csvin \u003e\u003e row) {\n    cout \u003c\u003c row[\"animal\"] \u003c\u003c \"\\n\";\n  }\n\n}\n```\n\nInput\n```console\n$ cat input.csv\nname,animal\nFergie,horse\nMyrtle II,chicken\nOscar,cat\n```\n\nCompile\n```console\n$ make example1\n  # OR\n$ g++ -std=c++11 example1.cpp -o example1\n```\n\nOutput\n```console\n$ ./example1\nhorse\nchicken\ncat\n```\n\n\n## Example 2: Read each row and each column with nested loops\nThis example has an outer loop for each row and an inner loop for each column.\n\n```c++\n//example2.cpp\n#include \"csvstream.hpp\"\n#include \u003ciostream\u003e\n#include \u003cstring\u003e\n#include \u003cmap\u003e\nusing namespace std;\n\n\nint main() {\n  // Open file\n  csvstream csvin(\"input.csv\");\n\n  // A row is a map\u003cstring, string\u003e, key = column name, value = datum\n  map\u003cstring, string\u003e row;\n\n  // Read file\n  while (csvin \u003e\u003e row) {\n    cout \u003c\u003c \"row:\" \u003c\u003c \"\\n\";\n    for (auto \u0026col:row) {\n      const string \u0026column_name = col.first;\n      const string \u0026datum = col.second;\n      cout \u003c\u003c \"  \" \u003c\u003c column_name \u003c\u003c \": \" \u003c\u003c datum \u003c\u003c \"\\n\";\n    }\n  }\n\n}\n```\n\nInput\n```console\n$ cat input.csv\nname,animal\nFergie,horse\nMyrtle II,chicken\nOscar,cat\n```\n\nCompile\n```console\n$ make example2\n  # OR\n$ g++ -std=c++11 example2.cpp -o example2\n```\n\nOutput.  Notice output order within each row is `animal` followed by `name`.  This is because iterating over a `map` yields items in sorted order by key.\n```console\n$ ./example2\nrow:\n  animal: horse\n  name: Fergie\nrow:\n  animal: chicken\n  name: Myrtle II\nrow:\n  animal: cat\n  name: Oscar\n```\n\n\n## Example 3: Maintaining order of columns in each row\nThis example uses a vector-of-pair to maintain the order of values read from each row.\n\n```c++\n// example3.cpp\n#include \"csvstream.hpp\"\n#include \u003ciostream\u003e\n#include \u003cstring\u003e\n#include \u003cvector\u003e\n#include \u003cutility\u003e\nusing namespace std;\n\n\nint main() {\n  // Open file\n  csvstream csvin(\"input.csv\");\n\n  // A row is a vector\u003cpair\u003cstring, string\u003e\u003e\n  // key = column name, value = cell datum\n  vector\u003cpair\u003cstring, string\u003e\u003e row;\n\n  // Read file\n  while (csvin \u003e\u003e row) {\n    cout \u003c\u003c \"row:\" \u003c\u003c \"\\n\";\n    for (unsigned int i=0; i \u003c row.size(); ++i) {\n      const string \u0026column_name = row[i].first;\n      const string \u0026datum = row[i].second;\n      cout \u003c\u003c \"  \" \u003c\u003c column_name \u003c\u003c \": \" \u003c\u003c datum \u003c\u003c \"\\n\";\n    }\n  }\n\n}\n```\n\nInput\n```console\n$ cat input.csv\nname,animal\nFergie,horse\nMyrtle II,chicken\nOscar,cat\n```\n\nCompile\n```console\n$ make example3\n  # OR\n$ g++ -std=c++11 example3.cpp -o example3\n```\n\nOutput.  Notice output order within each row is `name` followed by `animal`.  This is the order that the columns appear in the CSV file.\n```console\n$ ./example3\nrow:\n  name: Fergie\n  animal: horse\nrow:\n  name: Myrtle II\n  animal: chicken\nrow:\n  name: Oscar\n  animal: cat\n```\n\n\n## Changing the delimiter\nBy default, values in a row are delimited by a comma `,`.  Change the delimiter with the `delimiter` constructor parameter.\n\nThis example changes the delimiter to the `|` character.\n```c++\ncsvstream csvin(\"input.csv\", '|');\n```\n\n## Allow too many or too few values in a row\nBy default, if a row has too many or too few values, csvstream raises and exception.  With strict mode disabled, it will ignore extra values and set missing values to empty string.  You must specify a delimiter when using strict mode.\n```c++\ncsvstream csvin(\"input.csv\", ',', false);\n```\n\n## Error handling\nIf an error occurs, `csvstream` functions throw a `cstream_exception` .  For example:\n\n```c++\n// example4.cpp\n#include \"csvstream.hpp\"\n#include \u003ciostream\u003e\n#include \u003cstring\u003e\n#include \u003cmap\u003e\nusing namespace std;\n\n\nint main() {\n  // Open file\n  string filename = \"input.csv\";\n  try {\n    csvstream csvin(filename);\n    map\u003cstring, string\u003e row;\n    while (csvin \u003e\u003e row) {\n      cout \u003c\u003c row[\"animal\"] \u003c\u003c \"\\n\";\n    }\n  } catch(const csvstream_exception \u0026e) {\n    cerr \u003c\u003c e.what() \u003c\u003c \"\\n\";\n    return 1;\n  }\n}\n```\n","funding_links":[],"categories":["C++"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fawdeorio%2Fcsvstream","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fawdeorio%2Fcsvstream","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fawdeorio%2Fcsvstream/lists"}