parent
8d7d35ead5
commit
f3965cf6ee
@ -0,0 +1,41 @@
|
|||||||
|
#include "util.h"
|
||||||
|
|
||||||
|
std::array<std::vector<std::string>, 2> read_csv(const std::string& filename) {
|
||||||
|
std::array<std::vector<std::string>, 2> array_vectors;
|
||||||
|
std::vector<std::string> vec_option;
|
||||||
|
std::vector<std::string> vec_opcision;
|
||||||
|
std::ifstream file(filename);
|
||||||
|
std::string line;
|
||||||
|
char delimiter = ',';
|
||||||
|
getline(file, line);
|
||||||
|
while (std::getline(file, line)) {
|
||||||
|
std::stringstream stream(line);
|
||||||
|
std::string option;
|
||||||
|
std::string opcision;
|
||||||
|
getline(stream, option, delimiter);
|
||||||
|
getline(stream, opcision, delimiter);
|
||||||
|
vec_option.push_back(option);
|
||||||
|
vec_opcision.push_back(opcision);
|
||||||
|
}
|
||||||
|
array_vectors[0] = vec_option;
|
||||||
|
array_vectors[1] = vec_opcision;
|
||||||
|
return array_vectors;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string call(std::string cmd) {
|
||||||
|
FILE *fp;
|
||||||
|
int status;
|
||||||
|
char path[PATH_MAX] = {0};
|
||||||
|
fp = popen(cmd.c_str(), "r");
|
||||||
|
if (fp == NULL) {
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
while (fgets(path, PATH_MAX, fp) != NULL) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
status = pclose(fp);
|
||||||
|
if (status == -1) {
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
return path;
|
||||||
|
}
|
||||||
@ -0,0 +1,13 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <sstream>
|
||||||
|
#include <fstream>
|
||||||
|
#include <string>
|
||||||
|
#include <array>
|
||||||
|
#include <vector>
|
||||||
|
#include <linux/limits.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
std::array<std::vector<std::string>, 2> read_csv(const std::string& filename);
|
||||||
|
std::string call(std::string cmd);
|
||||||
Loading…
Reference in new issue