How can I check if a string contains char?

I have a text file that I want to read. I want to know if one of the lines contains [

so I tried:

if(array[i] == "[")

      

But it doesn't work.

How can I check if a string contains a specific character?

+12


source to share


2 answers


Look at the documentation string::find

string::find



std::string s = "hell[o";
if (s.find('[') != std::string::npos)
    ; // found
else
    ; // not found

      

+29


source


if the array is char * array or char array [], you can find char after a while:

while(i < nSize)
    if (array[i] == '[')

      



'[' is char, but "[" is a string

0


source







All Articles