Skip to content

Instantly share code, notes, and snippets.

@Drunkar
Last active August 4, 2016 10:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Drunkar/6078524 to your computer and use it in GitHub Desktop.
Save Drunkar/6078524 to your computer and use it in GitHub Desktop.
#include <fstream>
#include <vector>
#include <string>
#include <iostream>
template<typename T>inline std::vector< std::vector<T> >
tsv2Vrector(const std::string &filename, const int &num_column)
{
std::vector< std::vector<T> > table;
ifstream ifs;
ifs.open(fileName.c_str());
if(!ifs){
cerr << "Can't open "+fileName+"!\n";
} else {
cout << "Opened "+fileName+"." << endl;
// remove if no label.
std::string label;
for(int i=0; i<num_column; ++i) ifs >> label >> label;
while(!ifs.eof()){
vector<T> row;
for(int i=0; i<num_column; ++i){
T field;
ifs >> field;
row.push_back(field);
}
table.push_back(row);
// test
cout.setf(ios::fixed, ios::floatfield);
cout << row[0] << " " << row[1] << endl;
}
ifs.close();
cout << "closed "+fileName+"." << endl;
}
return table;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment