Q: String function in for loops for( it = str.begin(); it != str.end() && isspace( *it ); it++ ) ;
str.erase(str.begin(), it );

What exactly is this loop is doing?

A: for( it = str.begin(); it != str.end() && isspace( *it ); it++ ) ;

This line positions an iterator at the beginning of a string (str.begin()). The condition it != str.end() && isspace( *it ) says in plain english "while the end of the string has not been reached AND the current character is a space, increment the iterator."
Next
str.erase(str.begin(), it );

This erases the part of the string from its begin to the iterator. In clear terms, it trims any whitespace at the beginning of a string.
EDIT : Please read the comment below, it adds useful information to the answer.

A: This code is too clever for its own good - there are good reasons for not condensing code too much vertically.
Loop-confusion is one of them.
Rewriting a bit
for( it = str.begin(); it != str.end() && isspace(*it); it++ )
    ;
str.erase(str.begin(), it );

or, equivalently
for( it = str.begin(); it != str.end() && isspace(*it); it++ )
{
    // Personally, I always put an "intentionally left empty" comment inside these.
}
str.erase(str.begin(), it );

makes it clear that the erase is outside the loop.
Rewriting the loop using while
it = str.begin();
while (it != str.end() && isspace(*it))
{
    it++;
}
str.erase(str.begin(), it );

makes it more obvious that it first locates the first non-space character in the string and then erases everything before it, i.e. trims leading whitespace.
(I prefer the while form myself.)

A: This code des two things.
The first one finds the first character in the string, which is not a white-space:
for( it = str.begin(); it != str.end() && isspace( *it ); it++ ) ;

The second removes all the characters till that character:
str.erase(str.begin(), it );

The combination of them: the code removes the white-space characters in the beginning of the string :)
