-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathCSVReader.cpp
More file actions
37 lines (27 loc) · 855 Bytes
/
CSVReader.cpp
File metadata and controls
37 lines (27 loc) · 855 Bytes
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
#include <boost/algorithm/string.hpp>
#include <fstream>
#include <vector>
#include <iostream>
#include "CSVReader/CSVReader.h"
CSVReader::CSVReader(std::string filename, std::string delim=";") :
fileName(filename), delimeter(delim)
{ return; }
//CSVReader::CSVReader (const CSVReader& orig) { }
CSVReader::~CSVReader () {return; }
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));
// std::cout << vec.size () << std::endl;
dataList.push_back(vec);
}
// Close the File
file.close();
return dataList;
}