首页 > 其他 > 详细

string字符的存取(10)

时间:2020-07-09 12:23:51      阅读:52      评论:0      收藏:0      [点我收藏+]

string中单个字符存取方式有两种

char& operator[](int n); //通过[]方式取字符

char& at(int n); //通过at方法获取字符

 1 #include <iostream>
 2 #include <string>
 3 using namespace std;
 4 
 5 void test_01()
 6 {
 7     int i = 0;
 8     string str1 = "abcdefghijklmnopqrstuvwxyz";
 9 
10     //
11     for (i; i < str1.size(); i++)
12     {
13         cout << str1[i] << " ";
14     }
15     cout << endl;
16 
17     //修改
18     str1.at(0) = A;//注意不是“”而是‘’
19     cout << str1 << endl;
20 }
21 
22 int main(void)
23 {
24     test_01();
25 
26     system("pause");
27     return 0;
28 
29 }

 

string字符的存取(10)

原文:https://www.cnblogs.com/huanian/p/13272899.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!