pad.mattdiesel.co.uk

Snippet - C++ Vector read/write methods

C++ Vector read/write methods (C++)


Created 2016-12-18 15:22:44.993710 by Matt.
Modified 2016-12-18 15:23:03.168000 by Matt.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <vector>
#include <iostream>
#include <fstream>
#include <algorithm>



int main(int argc, char const *argv[])
{
	std::ifstream ifs("test.txt");

	int n;
	std::vector<int> v;
	for (;;) {
		ifs >> n;
		if (!ifs) break;
		v.push_back(n);
	}

	std::for_each(v.begin(), v.end(), [](int& n){ std::cout << n << " "; });

	return 0;

}