How to find a char in a string

closed account (L6k21hU5)
I have to write a program where I need to find if a string in an array has a matching char in my char array. I was wondering if anyone could help me out and show or tell me how to do this been looking everywhere and no luck. Thanks.
can you give an example and show us what you have so far
sounds like you're looking for string::find_first_of, as in

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <string>
#include <iostream>
using namespace std;
int main()
{
    char chars[] = {'a', 'b', 'c'};
    string strings[] = {"foo", "bar", "baz", "xyzzy"};

    for(auto& s: strings)
        if(s.find_first_of(chars, 0, sizeof chars) != string::npos)
            cout << s << " matches!\n";
        else
            cout << s << " doesn't match!\n";
}

live demo: http://liveworkspace.org/code/4AxEol$2
closed account (L6k21hU5)
Its not to just find the first of. The program has the user to pick between a constant or a vowel into a char array the gets words from a text file into a string array, then i need to search all of the words and return the biggest.
Topic archived. No new replies allowed.