C++ 字串庫 - 開始



描述

它返回一個指向字串第一個字元的迭代器。

宣告

以下是 std::string::begin 的宣告。

   iterator begin();
const_iterator begin() const;

C++11

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

引數

返回值

它返回指向字串開頭的迭代器。

異常

從不丟擲任何異常。

示例

以下是 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;
}

示例輸出應如下所示:

Tutorials point  
string.htm
廣告
© . All rights reserved.