find_first_of, size_type and find_first_not_of

ok so i had some questions that this sites documentation couldnt clear up for me so here they are.

find_first_of:

I assume this finds the first instance of the characters in its parameters, so like this?

1
2
3
4
5
6
7
8
9
string findChar2 = ("This function will ^ find the first character specified");

string::size_type found2 = findChar2.find_first_of("^");

if(found2 != string::npos)
{
    cout << "The first instance of " << findChar2[found2];
    cout << " is at position " << found2 << '\n';
}  



find_first_not_of:

This one i also assume is doing something similar, it finds the first character that doesnt match the ones in its parameters correct?

1
2
3
4
5
6
7
8
9
10
11
12
13
string findChar = ("This function will find the first non-alphabetical character");

string::size_type found = findChar.find_first_not_of
                           (
                              "abcdefghijklmnopqrstuvwxyz "
                              "ABCDEFGHIJKLMNOPQRSTUVWXYZ "
                           );

if (found!=string::npos)
{
    cout << "The first non-alphabetic character is " << findChar[found];
    cout << " at position " << found << '\n';
}


size_type:

I used to know what this one did but its been a while i dont even have an idea what it does.

also what about find_last_not_of and find_last_of, what do those do? Im sure they function very similar to the other ones but what exactly do they do? you dont need to give a technical answer just a plain english answer will do and it will actually help me if it is.

Also when will these ever be useful?
Last edited on
size_type is an unsigned integral type (like unsigned long) that is suitable representing the size or a character position in the string. Typically, it is an alias for std::size_t
http://en.cppreference.com/w/cpp/types/size_t


> find_last_not_of and find_last_of, what do those do?

What their names suggest.
http://en.cppreference.com/w/cpp/string/basic_string/find_last_of
http://en.cppreference.com/w/cpp/string/basic_string/find_last_not_of
Topic archived. No new replies allowed.