Mega Code Archive

 
Categories / C++ Tutorial / String
 

Search for any of a set of characters In this case, find the first @ or period

#include <iostream> #include <cstring> using namespace std; int main() {   const char *url = "server.com";   const char *url2 = "Apache.org";   const char *emailaddr = "Herb@server.com";   const char *tld[] = { ".com", ".net", ".org" };   const char *p;   // Search for any of a set of characters. In this case, find the first @ or period.   p = strpbrk(emailaddr, "@.");   if(p) cout << "Found " << *p << endl;   return 0; }