Created
July 31, 2014 18:33
-
-
Save mtao/a77fa6020f9cc1a08e1f to your computer and use it in GitHub Desktop.
file_token_reader
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 <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