std::basic_string<CharT,Traits,Allocator>::begin, std::basic_string<CharT,Traits,Allocator>::cbegin
cppreference.net에서 가져옴
iterator begin();
|
(1) | (C++11부터 noexcept) (C++20부터 constexpr) |
const_iterator begin() const;
|
(2) | (C++11부터 noexcept) (C++20부터 constexpr) |
const_iterator cbegin() const noexcept;
|
(3) | (C++11부터) (C++20부터 constexpr) |
문자열의 첫 번째 문자를 가리키는 반복자를 반환합니다.
begin()는 다음을 반환합니다: 가변 또는 상수 반복자. 이는 *this의 const 특성에 따라 달라집니다.
cbegin()는 항상 상수 반복자를 반환합니다. 이것은 const_cast<const basic_string&>(*this).begin()과 동일합니다.
매개변수
(없음)
반환값
첫 번째 문자에 대한 반복자.
복잡도
상수.
참고 사항
libc++ 백포트는
cbegin()
를 C++98 모드로 제공합니다.
예제
이 코드 실행
#include <iostream> #include <string> int main() { std::string s("Exemplar"); *s.begin() = 'e'; std::cout << s << '\n'; auto i = s.cbegin(); std::cout << *i << '\n'; // *i = 'E'; // error: i is a constant iterator }
출력:
exemplar e
참고 항목
|
(C++11)
|
끝을 가리키는 반복자를 반환함
(public member function) |
|
시작을 가리키는 반복자를 반환함
(
std::basic_string_view<CharT,Traits>
의
public member function)
|