Vector output

I dont understand why its printing the word with 'a' it should print words without 'a' in string.
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
  

#include <iostream>
#include <string>
#include <vector>

using namespace std;
bool letter_checker(string w, char c) {
	int let_count=0;
	for(int i=0;i<w.length();i++){
		if(w[i]==c){
			let_count=let_count+1;
		}	
	}
	
	if(let_count==0){
	    //cout<<"t";
		return true;
	}
	else if(let_count>0)
	{
	    
		return false;
	}
}


int main()
{
    vector<string> x;
   
    x.push_back("ban");
    x.push_back("sldjf");
    for(int i=0;i<x.size();i++){
        cout<<x[i];
     }
    cout<<endl;
    char d='a';
    for(int i=0;i<x.size();i++){
        if(letter_checker(x[i],d)==true){
           x.erase(x.begin()+i);
           
        }
    }
    for(int i=0;i<x.size();i++){
        cout<<x[i]<<" ";
    }

    return 0;
}
It looks like you check function's logic is wrong. Also you really don't need that else if() or even an else in that function, just return the proper value before the function ends.

By the way do you know that std::string has functions to find() if something exists in the string?

Topic archived. No new replies allowed.