read_file.cc
#include <fstream>
#include <iterator>
template<typename Container>
bool read(const char* filename, Container& cont)
{
std::ifstream in(filename, std::ios_base::in | std::ios_base::binary);
if(!in)
return false;
in.unsetf(std::ios::skipws);
std::copy(
std::istream_iterator<typename Container::value_type>(in),
std::istream_iterator<typename Container::value_type>(),
std::back_inserter(cont));
return true;
}
#include <list>
#include <string>
int main(int, char*[])
{
std::list<char> x;
read(__FILE__, x);
std::string s;
read(__FILE__, s);
return 0;
}
0 件のコメント:
コメントを投稿