![]() |
C++ has in its definition a way to represent a sequence of characters as an object of the class. This class is called std:: string. The string class stores the characters as a sequence of bytes with the functionality of allowing access to the single-byte character. In this article, we are going to learn how to access individual characters in a C++ String. Example Input: Access Individual Characters in a C++ StringIn C++, you can access individual characters in a std::string using the array subscript [] operator. We need to just pass the index between the [] operator. Indexing of string starts with 0. C++ Program to Access Individual Characters in a StringC++
Output
First character: H Third character: l Time complexity: O(1) |
Reffered: https://www.geeksforgeeks.org
C++ |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 14 |