string at() in C++ (original) (raw)

Last Updated : 04 Oct, 2024

The **std:🧵: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++.

**Syntax

str.**at(idx)

Parameters

Return Value

Example of string::at()

C++ `

// 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)

Similar Reads