String At Function - C++ Programming Tutorial
C++ Course / Strings / String At Function

String At Function

BLUF: Mastering String At Function is a critical step in becoming a proficient C++ developer. This lesson provides a deep dive into the syntax, performance considerations, and real-world applications of this concept.
Key Performance Insight: String At Function

C++ is renowned for its efficiency. Learn how String At Function enables low-level control and high-performance computing in the tutorial below.

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.

Input Required

This code uses input(). Please provide values below:

Logic Practice
Install Logic Practice
Add to home screen for a faster app-like experience