Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checking if array contains char

Ok, this is what I have been trying to do, please correct me if I am wrong I am trying to check if myarray contains the char abcd. What I am thinking of doing it this way:

char* myarray[] = {
    "hello",
    "wooorld",
    "hi"};

if(myarray->Contains(abcd))
{
//do stuff
}

My question is, is there a better way of doing it?

like image 917
bLu3eYeZ Avatar asked Jun 27 '13 20:06

bLu3eYeZ


1 Answers

One way do it is to use std::string and std::vector with std::find algorithm:

 std::vector<std::string> strs{"hello","wooorld","hi"};
 std::string toFind = "abcd";
 if (std::find(strs.begin(), strs.end(), toFind) != strs.end())
 {
    std::cout <<" abcd exist in vector of strings";
 }
like image 107
taocp Avatar answered Sep 21 '22 05:09

taocp