How to check if string contains any char from another string

So I want to check if the string "picture" user inputs in the program contains any "illegal" characters. I also want to check if the vector<string> "edges" contains char '-'.This is a class' method function that is supposed the check that out. Input comes from another method function. This function gets information in the form Puzzle {edges, picture}. I don't know how should I write my code so that the search works. At the moment the find() function only gets empty parameters and that is why it doesn't work(tested it out with test prints).


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
bool Puzzle::is_illegal() const{
  vector<string> edges;
    string picture;
    string legal = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 -|/\\+*#@";
    vector<string>::iterator iteri2;
    string::iterator iteri;
    iteri2 = find(edges.begin(),edges.end(),"-");
    iteri = picture.begin();

    while(iteri <picture.end()){
        if( legal.find(*iteri)== legal.end()){
            cerr <<  << endl;
            break;
        }else {
            ++iteri;
            continue;
        }
    } return true;
    if (iteri2 != edges.end()){
        cerr <<  << endl;
        return false;

    }else{
        return true;
    } 
To find characters from another string: http://en.cppreference.com/w/cpp/string/basic_string/find_first_of
To find characters not from another string: http://en.cppreference.com/w/cpp/string/basic_string/find_first_not_of

I also want to check if the vector<string> "edges" contains char '-'
Clarify: should it be a string containing only a single character '-' or if there is a string containing character '-' somewhere in it (should "a-b" match or not)?

At the moment the find() function only gets empty parameters
It might be because your edges vector does not contain anything, as you did not place anything in it.
Topic archived. No new replies allowed.