How can I read integers from a file to the array of integers in c++? So that, for example, this file\'s content:
23
31
41
23
would become:<
Here's one way to do it:
#include
#include
#include
int main()
{
std::ifstream file("c:\\temp\\testinput.txt");
std::vector list;
std::istream_iterator eos, it(file);
std::copy(it, eos, std::back_inserter(list));
std::for_each(std::begin(list), std::end(list), [](int i)
{
std::cout << "val: " << i << "\n";
});
system("PAUSE");
return 0;
}