public member function
<string>
std::string::front
char& front();const char& front() const;
Access first character
Unlike member string::begin, which returns an iterator to this same character, this function returns a direct reference.
This function shall not be called on empty strings.
Parameters
noneReturn value
A reference to the first character in the string.If the string object is const-qualified, the function returns a
const char&. Otherwise, it returns a char&.Example
|
|
Output:
Complexity
Constant.Iterator validity
No changes.Data races
The container is accessed (neither the const nor the non-const versions modify the container).The reference returned can be used to access or modify characters. Concurrently accessing or modifying different characters is safe.
Exception safety
If the string is not empty, the function never throws exceptions (no-throw guarantee).Otherwise, it causes undefined behavior.
See also
- string::back
- Access last character (public member function)
- string::at
- Get character in string (public member function)
- string::operator[]
- Get character of string (public member function)