The POCO libraries provide a handy class for dealing with URIs.

A little example on how to use it can be found here.