The fragment provides a refinement of the resource specification usually interpreted as a single string. It provides directions to a secondary resource related to such main resource, such as the section in an article or a time-point in a video.
As usual, its semantics vary depending on the scheme, authority, path, and media type of the resource. In HTML, fragments are used as internal page references. This usage is called a "named anchor," referring to a section within a web page. The URL below points to the anchor "section2":
url_view u("https://www.example.com/index.html#section2"); assert(u.fragment() == "section2");
These functions do not throw. The URL fragment might also be empty or absent.
If the URL has no fragment, these functions return an empty string. The function
can be used to determine whether this empty string means there is no fragment
or an empty fragment string in the URL.
The URL reserved characters
/ may appear unencoded with URL fragments, as they are not
ambiguous with other URL components.
url_view u("https://www.example.com/index.html#code%20:a@b?c/d"); assert(u.fragment() == "code :a@b?c/d");