csv_read

View page source

Read a Csv File

Prototype

   vec_vec_str csv_read(const std::string& file_name)
      // ...
      return csv_table;

vec_vec_str

see vec_vec_str .

file_name

is the name of the file containing the csv file. Each row in this file ends with a newlines '\n'. The columns are separated by commas ',' . A comma at the end of a line means there is an empty value at the end of the corresponding row. There are no other special characters in this file.

csv_table

  1. The j-th column of the i-th row of the file contains the value csv_table[i][j] . The special characters '\n' and ',' are not included in these values.

  2. The row and column indices start at zero.

  3. csv_table.size() is the number of rows in the table

  4. csv_table[i].size() is the number of columns in the i-th row.

Example

xam_csv_read.cpp contains an example and test of this routine.