C++ string front() Function
Example
Get the first character of a string:
string txt = "Hello World!";
cout << txt.front();
Definition and Usage
The front() function returns the first character of a string.
You can also use it to change the first character, like txt.front() = 'J';.
The front function is defined in the <string> header file.
Tip: To get the last character, use back().
Syntax
string.front();
Parameter Values
None.
Technical Details
| Returns: | A reference to the first character of the string. |
|---|
Related Pages
Read more about strings in our String Tutorial.