Skip to content

Instantly share code, notes, and snippets.

@jeffhung
Created August 21, 2008 06:00
Show Gist options
  • Save jeffhung/6512 to your computer and use it in GitHub Desktop.
Save jeffhung/6512 to your computer and use it in GitHub Desktop.
bool config_db::update_from_csv(const char* csv_file)
{
try {
vector< vector<string> > data_table;
ifstream ifs(csv_file);
while (ifs) {
string line;
getline(ifs, line);
vector<string> tokens;
// splits line string delimited by ",", and save to tokens.
boost::split(tokens, line, is_any_of(","));
// push row
data_table.push_back(vector<string>());
data_table.back().swap(tokens);
}
// above may throw
this->data_table_.swap(data_table); // nothrow
return true;
}
catch (...) {
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment