C++ String Library - begin



Description

It returns an iterator pointing to the first character of the string.

Declaration

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

   iterator begin();
const_iterator begin() const;

C++11

   iterator begin() noexcept;
const_iterator begin() const noexcept;

Parameters

none

Return Value

It returns an iterator to the beginning of the string.

Exceptions

Never throw any exceptions.

Example

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

#include <iostream>
#include <string>

int main () {
   std::string str ("Tutorials point");
   for ( std::string::iterator it=str.begin(); it!=str.end(); ++it)
      std::cout << *it;
   std::cout << '\n';

   return 0;
}

The sample output should be like this −

Tutorials point  
string.htm
Advertisements