How to count amount of letters?

I have written the code to have the file specified read and shown on the screen. Then I have it so that way the letters are all shown. However, I want the letters to be shown like this:
T:1
H:1
E:2
etc. How can I go about doing so?
Here is the code
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <iostream>
#include<fstream>
#include <string>

using namespace std;

int main() {
char temp;
int i, j, length, pass;

string sentence;

int wordcount;
string words;

ifstream input;
	input.open("F:\\sentence.txt");
	
	getline(input,sentence);
		

	length = sentence.length();


	for(i = 0; i < length; i++)
	{
		sentence[i] = tolower(sentence[i]);
		
		cout << sentence[i];
	}
	
	cout << endl << endl;
	
	system("pause");

	for(pass = 1; pass < length; pass++)
	{
		for(j = 0; j < length - 1; j++)
		{
			if(sentence[j] > sentence[j+1])
			{
				temp = sentence[j];
				sentence[j] = sentence[j+1];
				sentence[j+1] = temp;
			}

		}
	}

	for(i = 0; i < length; i++)
	{
		{
 if(sentence[i] == ' ' || sentence[i] == '.')
 {
 sentence[i];
 
}
		}
 
		cout << sentence[i];
	}
	

	cout << endl << endl;

	system("pause");

	return 0;
}


The sentence is: the boy waved.
This might work for strings, not sure though:
http://www.cplusplus.com/reference/algorithm/count/

MAKE SURE TO INCLUDE #include <algorithm>
Last edited on
Topic archived. No new replies allowed.