iterator begin(); |
begin()函数返回一个迭代器,指向字符串的第一个元素.
返回值是字符串的首地址,取值为*
举例
string testbegin = "Hello World";
string::iterator it;
for(it = testbegin.begin(); it<testbegin.end(); it++)
cout<<*it;
//打印结果为 Hello World
-----------------------------------------------------------
iterator begin();const_iterator begin() const;
Returns an iterator referring to the first character in the string.
Parameters
none
Return Value
An iterator to the beginning 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
| |
This code prints out the content of a string character by character using an iterator that iterates between begin and end.