public member function
<string>

std::basic_string::cbegin

const_iterator cbegin() const noexcept;
返回指向開頭的 const_iterator
返回一個const_iteratorpointing to the first character of the string.

Aconst_iterator是一個指向常量內容的迭代器。這個迭代器可以像iteratorreturned by basic_string::begin, but it cannot be used to modify the contents it points to, even if the basic_string object is not itself const.

引數



返回值

Aconst_iteratorto the beginning of the string.

成員型別const_iterator是指向 const 字元的隨機訪問迭代器型別。

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
// string::cbegin/cend
#include <iostream>
#include <string>

int main ()
{
  std::string str ("Lorem ipsum");
  for (auto it=str.cbegin(); it!=str.cend(); ++it)
    std::cout << *it;
  std::cout << '\n';

  return 0;
}

輸出
Lorem ipsum


複雜度

未指定,但通常是恆定的。

迭代器有效性

沒有變化。

資料競爭

該物件被訪問。

異常安全

無異常保證:此成員函式從不丟擲異常。
還可以保證返回的迭代器的複製構造或賦值永遠不會引發異常。

另見