Increment specific vectorelements

I want to increment specific vector elements. I am opening and reading from a file and want to count how many a, b, c and all the way to z I have. I have made a vector with 26 "locations" so that v[0] will have the count of how many a's I have, and so on. But, when I search for the characters in my file, how do I increment v[0] to 1 when I find an 'a'?

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
  void drawStatistics()
{
    
    cout << "Which file will you read from? ";
    string iname;
    cin >> iname;
    ifstream in {iname};
    if (!in) error("cant open inputfile ", iname);
    
    vector<int> characterCount[26];
    char letter;
   
    
    while ( inn >> letter )
    {
        inn >> letter;
        letter = tolower(letter);
        
        if ( letter >= 'a' && letter <= 'z' )
        {
            //I tried doing something like this but I get an error message.
            characterCount[letter - 'a']++;
        }
        
}
    
}
This creates an array of 26 empty vectors.
 
vector<int> characterCount[26];

To call the vector's constructor you need to use parentheses.
 
vector<int> characterCount(26);
Last edited on
Oh gosh, rookie mistake. Thank you:-)
Registered users can post here. Sign in or register to post.