Created
November 6, 2018 05:41
-
-
Save JVero/7556d5af424bfc6bf240e49b6b3635b6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<fstream> | |
#include<string> | |
#include<iostream> | |
#include<vector> | |
std::vector<std::string> split_string(std::string string_input, char delimeter) { | |
std::vector< std::string > split_strings; | |
std::string thing; | |
for (auto a: string_input){ | |
if (a == delimeter) { | |
split_strings.push_back(thing); | |
thing.clear(); | |
} else { | |
thing.push_back(a); | |
} | |
} | |
if (thing.size()){ | |
split_strings.push_back(thing); | |
} | |
return split_strings; | |
} | |
std::vector < std::vector< std::string > > split_csv(std::string file_name, char delimeter) { | |
std::fstream file(file_name); | |
std::vector< std::vector< std::string> > return_value; | |
std::string chunk; | |
while (std::getline(file,chunk )) { | |
return_value.push_back(split_string(chunk, delimeter)); | |
} | |
return return_value; | |
} | |
int main(){ | |
auto resp = split_csv("file.csv", ','); | |
for (auto a: resp) { | |
std::cout << "line" << std::endl; | |
for (auto l: a) { | |
std::cout << l <<std::endl; | |
} | |
} | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment