string begin() in C++

begin(): It returns a read/write iterator that points to the first character in the string.

Parameter: No parameter required.

Syntax:

string ::iterator it = str.begin()

For Example:

str = "abc"

str.begin() => It returns iterator to the first character of string (i.e a)

Approach

C++

#include <bits/stdc++.h>
using namespace std;

int main()
{
    string str = "abc";

    string ::iterator it = str.begin();
    cout << *it << "\n";

    return 0;
}


No comments:

Post a Comment