error using vectors with strings

hey guys i know this question has been asked a lot but still geting errors...i want the user to input a string and in dat string output the number of "A,s" in the string but i get an error saying unknown operator "=="....this problem always occurs when using vectors....and want to store my string in vector if dats even possible..pleaaaase help..thanx in advance

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
  #include <iostream>
#include <vector>
#include <fstream>
#include <string>

using namespace std;
void getvaluesfromfile(vector<string>&Word)
{
    string word;
    ifstream infile("input.txt");
    while(getline(infile,word))
    {
        Word.push_back(word);
    }
}
void calculatevowel(vector<string>Word)
{
    int numa=0;
    int nums=0;
    for(unsigned int i=0;i<Word.size();i++)
    {
        if(Word.at(i)=='a')
        {
            numa++;
        }
        else if(Word.at(i)=='  ' )
        {
            nums--;
        }
    }
    cout<<numa<<endl;
}

int main()
{
    vector<string> Word;
    getvaluesfromfile(Word);
    calculatevowel(Word);

    return 0;
}
You have a container of strings not characters so you must use double quotes on lines 22 and 26. Though if you wish to iterate over each character you probably want another for loop after the first one like: for(unsigned int j = 0; j <Word.at(i).size(); ++j) or using iterators or a ranged-based loop.
Topic archived. No new replies allowed.