Skip to content

Instantly share code, notes, and snippets.

@mtao
Created July 31, 2014 18:33
Show Gist options
  • Save mtao/a77fa6020f9cc1a08e1f to your computer and use it in GitHub Desktop.
Save mtao/a77fa6020f9cc1a08e1f to your computer and use it in GitHub Desktop.
file_token_reader
#include <fstream>
#include <sstream>
#include <iostream>
#include <iterator>
#include <vector>
int main(int argc, char * argv[]) {
if(argc < 2) {
std::cout << "Nothing here!" << std::endl;
return 1;
}
std::ifstream ifs(argv[1]);
for(std::string line; std::getline(ifs,line);) {
std::istringstream iss(line);
std::vector<std::string> tokens;
std::copy(std::istream_iterator<std::string>(iss)
, std::istream_iterator<std::string>()
, std::back_insert_iterator<std::vector<std::string> >(tokens));
for(auto&& t: tokens) {
std::cout << t << " ";
}
std::cout << std::endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment