Simple vector issue


Hi, I am new to C++. I am trying to create a vector that can hold strings. I have a while (cin >> entry) statement to capture all string inputs in a vector container, but when I hit Ctrl-D, it does not get an EOF signal... If I change the type to int, it works. Any thoughts ?

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
26
#include <iostream>
#include <string>
#include <iomanip>
#include <ios>
#include <algorithm>
#include <vector>

using namespace std;

int main() {
	cout << "This program counts the number of times distinct words appear in an input" << endl;

	vector<string> input;
	string entry;
        cout << "Enter strings: ";

	while (cin >> entry) {
		input.push_back(entry);
	}

        // it stops working here ... I should be able to ctrl-d for EOF
	
	cout << "bye ...";

	return 0;
}
Are you on unix/linux or windows? On windows EOF is ctrl-z.
Last edited on
Windows. Neither CTRL-Z nor CTRL-D works. Works only if I change the type to int. ...
ctrl-z works on mine. windows xp.
use getline() function instead of cin. I guess it will solve the problem
Topic archived. No new replies allowed.