Extract txt to vector
Hi guys im trying to extract this
1 2 3 4
5 7 8
9 6 10 11
13 14 15 12
into a vector where the blank space can variate and the numbers can switch.How can i get this working?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
#include <algorithm>
#include <fstream>
#include <iostream>
#include <istream>
#include <iterator>
#include <vector>
std::vector<int> read_numbers(std::istream &is)
{
int temp;
std::vector<int> r;
while (is >> temp)
r.push_back(temp);
return r;
}
int main()
{
std::ifstream input_file("nunks_input.txt");
std::vector<int> numbers(read_numbers(input_file));
std::copy(numbers.begin(), numbers.end(), std::ostream_iterator<int>(std::cout, " "));
}
|
Topic archived. No new replies allowed.