Home > Fresh News > Load a file to a string list

Load a file to a string list

January 22nd, 2010 Leave a comment Go to comments
#include <vector>
#include <string>
#include <iostream>
#include <fstream>
#include <algorithm>
#include <iterator>

int main(int argc, char* argv[])
{
    std::vector<std::string> v;
    std::ifstream f("e:/test.txt");
    if(f.is_open())
    {
        std::copy(std::istream_iterator<std::string>(f),
                  std::istream_iterator<std::string>(),
                  std::back_inserter(v));
    }
    // проверка
    std::copy(v.begin(), v.end(),
              std::ostream_iterator<std::string>(std::cout, "\n"));

    return 0;
}

rsdn.ru

  1. No comments yet.
  1. No trackbacks yet.
You must be logged in to post a comment.