You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 lines
1.4 KiB
C++
63 lines
1.4 KiB
C++
#include "boilerplate.hh"
|
|
|
|
// newline separated split, int
|
|
std::vector<int> readFileInt(std::string file){
|
|
std::vector<int> 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(stoi(line));
|
|
}
|
|
return outputVec;
|
|
}
|
|
|
|
// newline separated split, string
|
|
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;
|
|
} |