Home
>
Fresh News > Load a file to a string list
Load a file to a string list
#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