string at() in C++ Last Updated : 04 Oct, 2024 Comments Improve Suggest changes Like Article Like Report 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++.Syntaxstr.at(idx)Parametersidx: Index at which we have to find the character.Return ValueReturns the character at the given index of the string.If the given index is less than 0 or greater than equal to the length of string, then it throws an out_of_range exception.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; } OutputG F e Time Complexity: O(1)Auxiliary Space: O(1) Comment More info P Pushpanjali chauhan Improve Article Tags : Misc C++ STL CPP-Functions cpp-strings-library +1 More Explore C++ BasicsIntroduction to C++3 min readData Types in C++7 min readVariables in C++4 min readOperators in C++9 min readBasic Input / Output in C++5 min readControl flow statements in Programming15+ min readLoops in C++7 min readFunctions in C++8 min readArrays in C++8 min readCore ConceptsPointers and References in C++5 min readnew and delete Operators in C++ For Dynamic Memory5 min readTemplates in C++8 min readStructures, Unions and Enumerations in C++3 min readException Handling in C++11 min readFile Handling through C++ Classes8 min readMultithreading in C++8 min readNamespace in C++5 min readOOP in C++Object Oriented Programming in C++8 min readInheritance in C++10 min readPolymorphism in C++5 min readEncapsulation in C++4 min readAbstraction in C++4 min readStandard Template Library(STL)Standard Template Library (STL) in C++3 min readContainers in C++ STL3 min readIterators in C++ STL10 min readC++ STL Algorithm Library3 min readPractice & ProblemsC++ Interview Questions and Answers1 min readC++ Programming Examples4 min read Like