find [C++ Reference]
Keywords: string,find
Date: 2008-11-15T03:25:12-0800

[[find]]
C++ Reference
Translations of this page?:

- en
- br-pt
- cn
- fr
- it
- jp
- pl
- ru
- tr

## find

Syntax:

        #include <string>
        size_type find( const string& str, size_type index = 0 ) const;
        size_type find( const char* str, size_type index = 0 ) const;
        size_type find( const char* str, size_type index, size_type length ) const;
        size_type find( char ch, size_type index = 0 ) const;

The function find() returns either:

- the first occurrence of str within the current string, starting at index, or string::npos if nothing is found
- the first length characters of str within the current string, starting at index, or string::npos if nothing is found.

For example:

         string str1( "Alpha Beta Gamma Delta" );
         string::size_type loc = str1.find( "Omega", 0 );
         if( loc != string::npos ) {
           cout << "Found Omega at " << loc << endl;
         } else {
           cout << "Didn't find Omega" << endl;
         }

Related Topics: find_first_not_of, find_first_of, find_last_not_of, find_last_of, rfind

Edit this page • Old revisions
• • • Login • Index • Recent changes • RSS • cc •