Accessing Characters β at()
Generally, we can access the character of a string using the [] array subscript operator and indexing. But std::string also has a function named at() which can be used to access the characters of the string.
Syntax
string_object.at(index);
Parameters
- index: It represents the position of the character in the string.
Return Value
- This function returns the character present at the index.
Example
std::string str = "w3wiki"; std::cout << str.at(3);
The std::cout will print K on the console as it is the character present at index 3.
String Functions In C++
A string is referred to as an array of characters. In C++, a stream/sequence of characters is stored in a char array. C++ includes the std::string class that is used to represent strings. It is one of the most fundamental datatypes in C++ and it comes with a huge set of inbuilt functions. In this article, will look at the functions of string computations.
Contact Us