打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
basic_string

Returns an iterator addressing the first element in the string.

const_iterator begin( ) const;iterator begin( );

Return Value

A random-access iterator that addresses the first element of the sequence or just beyond the end of an empty sequence.

Remark

If the return value of begin is assigned to a const_iterator, the string object cannot be modified. If the return value of begin is assigned to an iterator, the string object can be modified.

Example

// basic_string_begin.cpp// compile with: /EHsc#include <string>#include <iostream>int main( ) {   using namespace std;   string str1 ( "No way out." ), str2;   basic_string <char>::iterator strp_Iter, str1_Iter, str2_Iter;   basic_string <char>::const_iterator str1_cIter;   str1_Iter = str1.begin ( );   cout << "The first character of the string str1 is: "         << *str1_Iter << endl;   cout << "The full original string str1 is: " << str1 << endl;   // The dereferenced iterator can be used to modify a character   *str1_Iter = 'G';   cout << "The first character of the modified str1 is now: "         << *str1_Iter << endl;   cout << "The full modified string str1 is now: " << str1 << endl;   // The following line would be an error because iterator is const   // *str1_cIter = 'g';   // For an empty string, begin is equivalent to end   if (  str2.begin ( ) == str2.end ( ) )      cout << "The string str2 is empty." << endl;   else      cout << "The string str2 is not empty." << endl;}

Output

The first character of the string str1 is: NThe full original string str1 is: No way out.The first character of the modified str1 is now: GThe full modified string str1 is now: Go way out.The string str2 is empty.

See Also

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
STL set 的详细用法
C 实现离散数学求主合取范式和主析取范式
C++ vector 类学习笔记 - C/C++ - 在路上
vector用法总结
C#与C++相比较之STL篇
C++ replace() 函数用法详解
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服