C++ String Library - front



Description

It returns a reference to the first character of the string.

Declaration

Following is the declaration for std::string::front.

char& front();

C++11

const char& front() const;

Parameters

none

Return Value

It returns a reference to the first character of the string.

Exceptions

if an exception is thrown, there are no changes in the string.

Example

In below example for std::string::front.

#include <iostream>
#include <string>

int main () {
   std::string str ("Sairamkrishna Mammahe");
   str.front() = 'A';
   std::cout << str << '\n';
   return 0;
}
Aairamkrishna Mammahe
string.htm
Advertisements