How to initialize vector from text file in C++

1 Answer

0 votes
#include <iostream>
#include <vector>
#include <fstream>

using std::cout;
using std::endl;
using std::vector;

int main()
{
	std::ifstream from_file("d:\\data.txt", std::ios::binary);

	vector<char> vec((std::istreambuf_iterator<char>(from_file)),
				      std::istreambuf_iterator<char>());

	for (char i = 0; i < vec.size(); i++) 
		cout << vec[i];

	cout << endl;

	return 0;
}


/*
run:

python
java
c#
php
c++

*/

 



answered May 19, 2018 by avibootz

Related questions

...