init
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
#include "boilerplate.hh"
|
||||
|
||||
// newline separated split
|
||||
std::vector<std::string> readFile(std::string file){
|
||||
std::vector<std::string> outputVec;
|
||||
|
||||
std::ifstream inputFile(file);
|
||||
if (!inputFile.is_open()){
|
||||
std::cerr << "File " << file << "not found";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
std::string line;
|
||||
while(getline(inputFile, line)){
|
||||
outputVec.push_back(line);
|
||||
}
|
||||
return outputVec;
|
||||
}
|
||||
|
||||
// newline, and delimited split
|
||||
InputArrays readFile(std::string file, char delim){
|
||||
InputArrays outputVec;
|
||||
|
||||
std::ifstream inputFile(file);
|
||||
if (!inputFile.is_open()){
|
||||
std::cerr << "File " << file << "not found";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
std::string line;
|
||||
while(getline(inputFile, line)){
|
||||
outputVec.push_back(ssplit(line, delim));
|
||||
}
|
||||
return outputVec;
|
||||
}
|
||||
|
||||
std::vector<std::string> ssplit(std::string str, char delimiter){
|
||||
std::vector<std::string> output;
|
||||
std::istringstream iss(str);
|
||||
|
||||
std::string split;
|
||||
while(getline(iss, split, delimiter)){
|
||||
output.push_back(split);
|
||||
}
|
||||
return output;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
#ifndef BOILERPLATE_HH
|
||||
#define BOILERPLATE_HH
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
using InputArrays = std::vector<std::vector<std::string>>;
|
||||
|
||||
InputArrays readFile(std::string, char);
|
||||
std::vector<std::string> readFile(std::string);
|
||||
std::vector<std::string> ssplit(std::string, char);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user