-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathndgp.h
51 lines (43 loc) · 1.06 KB
/
ndgp.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Read in a csv file
#ifndef CSVReader_H
#define CSVReader_H
#include <fstream>
#include <vector>
#include <iterator>
#include <string>
#include <algorithm>
#include <boost/algorithm/string.hpp>
/*
* A class to read data from a csv file.
*/
class CSVReader
{
std::string fileName;
std::string delimeter;
public:
CSVReader(std::string filename, std::string delm = ",") :
fileName(filename), delimeter(delm)
{ }
// Function to fetch data from a CSV File
std::vector<std::vector<std::string> > getData();
};
/*
* Parses through csv file line by line and returns the data
* in vector of vector of strings.
*/
std::vector<std::vector<std::string> > CSVReader::getData()
{
std::ifstream file(fileName);
std::vector<std::vector<std::string> > dataList;
std::string line = "";
// Iterate through each line and split the content using delimeter
while (getline(file, line))
{
std::vector<std::string> vec;
boost::algorithm::split(vec, line, boost::is_any_of(delimeter));
dataList.push_back(vec);
}
// Close the File
file.close();
return dataList;
}