Last Updated : 04 Oct, 2024
The std::string::at() in C++ is a built-in function of std::string class that is used to extract the character from the given index of string. In this article, we will learn how to use string::at() in C++.
SyntaxParametersstr.at(idx)
// C++ Program to show, how to use string::at()
// for extracting the character from given index
#include <bits/stdc++.h>
using namespace std;
int main() {
string str("GeeksForGeeks");
// Extracting the character of 0th index
cout << str.at(0) << endl;
// Extracting the character of 5th index
cout << str.at(5) << endl;
// Extracting the character of 9th index
cout << str.at(9) << endl;
return 0;
}
Time Complexity: O(1)
Auxiliary Space: O(1)
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4