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 infoAdvertise with us Next Article string at() in C++ P Pushpanjali chauhan Improve Article Tags : Misc C++ STL CPP-Functions cpp-strings-library +1 More Practice Tags : CPPMiscSTL Similar Reads Strings in C++ In C++, strings are sequences of characters that are used to store words and text. They are also used to store data, such as numbers and other types of information in the form of text. Strings are provided by <string> header file in the form of std::string class.Creating a StringBefore using s 5 min read Strings in C A String in C programming is a sequence of characters terminated with a null character '\0'. The C String is work as an array of characters. The difference between a character array and a C string is that the string in C is terminated with a unique character '\0'.DeclarationDeclaring a string in C i 5 min read std::basic_string::at in C++ Returns a reference to the character at the specified location pos. The function automatically checks whether pos is the valid position of a character in the string (i.e., whether pos is less than the string length), throwing an out_of_range exception if it is not. Syntax: reference at (size_type po 1 min read Array of Strings in C++ In C++, a string is sequence of characters that is used to store textual information. Internally, it is implemented as a dynamic array of characters. Array of strings is the array in which each element is a string.We can easily create an array of string in C++ as shown in the below example:C++#inclu 4 min read String find() in C++ In C++, string find() is a built-in library function used to find the first occurrence of a substring in the given string. Letâs take a look at a simple example that shows the how to use this function:C++#include <bits/stdc++.h> using namespace std; int main() { string s = "Welcome to GfG!"; s 4 min read Like