c 2b 2b load file as vector

Solutions on MaxInterview for c 2b 2b load file as vector by the best coders in the world

showing results for - "c 2b 2b load file as vector"
Jessica
09 Mar 2020
1#include <iostream>
2#include <iterator>
3#include <fstream>
4#include <vector>
5#include <algorithm> // for std::copy
6
7int main()
8{
9  std::ifstream is("numbers.txt");
10  std::istream_iterator<double> start(is), end;
11  std::vector<double> numbers(start, end);
12  std::cout << "Read " << numbers.size() << " numbers" << std::endl;
13
14  // print the numbers to stdout
15  std::cout << "numbers read in:\n";
16  std::copy(numbers.begin(), numbers.end(), 
17            std::ostream_iterator<double>(std::cout, " "));
18  std::cout << std::endl;
19
20}
21