public member function

std::string::end

<string>
      iterator end();
const_iterator end() const;
Return iterator to end
Returns an iterator referring to the next element after the last character in the string.

Parameters

none

Return Value

An iterator past the end of the string.

The type of this iterator is either string::iterator member type or string::const_iterator member type, which are compiler specific iterator types suitable to iterate through the elements of a string object.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
// string::begin and string::end
#include <iostream>
#include <string>
using namespace std;

int main ()
{
  string str ("Test string");
  string::iterator it;
  for ( it=str.begin() ; it < str.end(); it++ )
    cout << *it;
  return 0;
}


This code prints out the content of a string character by character using an iterator that iterates between begin and end.

Basic template member declaration

( basic_string<charT,traits,Allocator> )
1
2
      iterator end();
const_iterator end() const;


See also