ECF 1.5
ReadData.h
1#include<vector>
2
3//
4// reads delimited data from file; returns data as vector of vectors
5//
6template <class T>
7bool readDataFromFile(std::vector< vector<T> >& data, string fileName)
8{
9 ifstream file(fileName.c_str());
10 if(!file)
11 return false;
12
13 data.clear();
14 string line;
15 uint instance = 0;
16
17 while(getline(file, line)) {
18 vector<T> set;
19 data.push_back(set);
20 stringstream ss(line);
21 T datum;
22 while(ss >> datum)
23 data[instance].push_back(datum);
24 instance++;
25 }
26
27 return true;
28}