Home » C++ String cbegin() function

C++ String cbegin() function

by Online Tutorials Library

C++ String cbegin()

It gives a reference to the first element of the string.

Difference b/w cbegin() and begin()

The only difference between cbegin() and begin() is cbegin() returns the constant iterator pointing to the constant value.

Syntax

Consider a string str. Its syntax would be:

Parameter

This function does not contain any parameter.

Return value

This function returns the reference pointing to the first element of the string.

Example 1

Let’s see a simple example:

In this example, string ‘java tutorial’ is displayed using cbegin() function.

Output:

java tutorial   

Example 2

Let’s see another simple example:

Output:

12345  

In this example, vector containing integer values are displayed using cbegin().

Next TopicC++ Strings

You may also like