Skip to content

Instantly share code, notes, and snippets.

@Loki-Astari
Created June 30, 2016 15:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Loki-Astari/ac8763f0032ad27819c0d687a6732810 to your computer and use it in GitHub Desktop.
Save Loki-Astari/ac8763f0032ad27819c0d687a6732810 to your computer and use it in GitHub Desktop.
#include <iterator>
#include <fstream>
#include <iostream>
template<typename T>
class FWrapper
{
std::ifstream& file;
public:
FWrapper(std::ifstream& file)
: file(file)
{}
std::istream_iterator<T> begin() {return std::istream_iterator<T>(file);}
std::istream_iterator<T> end() {return std::istream_iterator<T>();}
};
int main()
{
std::ifstream f("data");
FWrapper<char> file(f);
for(auto x: file)
{
std::cout << x << " ";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment