Using STL to count the number of occurence of english letter

Hi,

The code is written to count the number of occurence of english letter from user's input. The problem I am having now is that when the input contain "enter", the program will end. But it is supposed to end the program using "ctrl+D". So how can I solve this problem?

Thank you for your attention!

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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <iostream>
#include <map>
#include <string>
#include <algorithm>
#include <sstream>

using namespace std;

class CharCount{
private:
	map<char, int> count;

public:
	void operator()(char f){
		if(isalpha(f)){
			f= toupper(f);		
			count[f]++;
		}
	}
	
	void display(){
		map<char, int>::iterator it;
		for (it=count.begin();it!=count.end();it++){
			cout<<(*it).first << " " << (*it).second << endl;
		}
	}
};



int main(){
	CharCount c;
	string line;
	getline(cin, line);

	istringstream iss;
	string word;
	while (iss>>word){	  
		  c= for_each(word.begin(),word.end(),c);
	}
	
	c.display();
	
	return 0; 
}
Your variable istringstream iss; has no any data.
Did you mean istringstream iss( line );?
Last edited on
thank you for your response!
but i use (iss>>word) to input data
One more your variable istringstream iss; is empty. How many times should I repeat this to you?!
Topic archived. No new replies allowed.