Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,860 questions

51,781 answers

573 users

How to read integers from input into a vector in C++

1 Answer

0 votes
#include <iostream>
#include <vector>
#include <iterator>
#include <algorithm>

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

int main()
{
	vector<int> vec(3);

	cout << "Enter 3 integers: ('e' to end)" << endl;

	std::istream_iterator<int> is_it(cin);

	copy(is_it, std::istream_iterator<int>(), vec.begin());

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

	cout << endl;

	return 0;
}


/*
run:

Enter 3 integers: ('e' to end)
76
98
12
e
76 98 12

*/

 



answered May 19, 2018 by avibootz

Related questions

1 answer 205 views
1 answer 152 views
1 answer 151 views
1 answer 134 views
1 answer 103 views
1 answer 131 views
1 answer 129 views
...