C++ String at
This function is utilized for retrieving specific characters.
Syntax
To determine the index of a specific character within a string, the syntax to be used is:
Example
str.at(pos);
Parameters
It specifies the location of the character in the string.
Return value
It retrieves the character indicated at the specified position.
Example 1
Example
#include<iostream>
using namespace std;
int main()
{
string str = "Welcome to javacpptutorial 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;
}
Output:
Output
String contains Welcome to javacpptutorial tutorial
The example illustrates how we can retrieve characters by utilizing either the at member function or the subscript operator.