<<<Index>>>

Search


    #include <cassert>
    #include <string>
    using std::string;
    void main()
    {
        string s1 = "Hello world";
        // Find a substring (from front or back)
        int pos = s1.find("worl");  // returns 6:
                                    assert( pos == 6 );
        pos = s1.find("foo");       // returns string::npos
                                    assert( pos == string::npos );
        pos = s1.find('o');         // returns 4:
                                    assert( pos == 4 );
        pos = s1.rfind('o');        // returns 7:
                                    assert( pos == 7 );
        // Find any character (from front or back)
        pos = s1.find_first_of( "aeiou" );  // returns 1;
                                            assert( pos == 1 );
        pos = s1.find_first_not_of( "aeiou" );  // returns 0;
                                                assert( pos == 0 );
    }
<<<Index>>>