C++教程
C++控制语句
C++函数
C++数组
C++指针
C++对象
C++继承
C++多态
C++抽象
C++常用
C++ STL教程
C++迭代器
C++程序

C++ String at()

C++ String at()

此函数用于访问单个字符。

语法

考虑字符串str。要找到特定字符的位置,其语法应为
str.at(pos);

参数

pos: 它定义了字符在字符串中的位置。

返回值

它返回在该位置指定的字符。

示例1

#include<iostream>
using namespace std;
int main()
{
string str = "Welcome to lidihuo tutorial";
cout<<"String contains :";
for(int i=0; i<str.length(); i++)
{
cout<<  str.at(i);
} 
cout<<'\n';
cout<<"String is shown again";
for(int j=0 ; j<str.length(); j++)
{
cout<< str[j];
}
return 0;
} 
输出:
String contains Welcome to lidihuo tutorial
示例显示我们可以使用成员函数at()或下标运算符[]访问字符。

昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4