How to search for a particular character in a C++ string ?

By | July 11, 2011

Hi,

In order to search for a particular character in a C++ string, use the following code.

#include <iostream>
#include <cstring>
 
using namespace std;
 
int main() {
 
  const char *testStr= "coderz@heaven";
 
  const char *temp;
 
  // Searching
  temp = strchr(testStr, '@');
 
  if(temp )
 
      cout << "Found";
 
  return 0;
}

Leave a Reply

Your email address will not be published. Required fields are marked *