How to Access Individual Characters in a C++ String? Last Updated : 21 Feb, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report 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:myString = "GeeksforGeeks";Output:4th Character = kAccess 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 String C++ // C++ Program to Access Individual Characters in a String #include <iostream> #include <string> // Driver Code int main() { std::string str = "Hello"; // Accessing individual characters using iterators std::string::iterator it = str.begin(); char firstChar = *it; // Accessing the first character // You can also use ++ operator to move the iterator ++it; // Move to the next character ++it; // Move to the third character char thirdChar = *it; std::cout << "First character: " << firstChar << std::endl; std::cout << "Third character: " << thirdChar << std::endl; return 0; } OutputFirst character: H Third character: l Time complexity: O(1)Space Complexity: O(1) Comment More infoAdvertise with us Next Article How to Convert a std::string to char* in C++? M mohitrajora Follow Improve Article Tags : C++ Programs C++ cpp-strings CPP Examples Practice Tags : CPPcpp-strings Similar Reads How to Convert a Single Character to String in C++? A string is a generally made up of a sequence of multiple characters. In this article, we will learn how to convert a single character to a string in C++.Example:Input: c = 'A'Output: s = "a"Explanation: Character c is converted to a string.Input: c = '#'Output: s = "#"Explanation: Character c is co 4 min read Convert character array to string in C++ This article shows how to convert a character array to a string in C++. The std::string in c++ has a lot of inbuilt functions which makes implementation much easier than handling a character array. Hence, it would often be easier to work if we convert a character array to string. Examples: Input: ch 4 min read How to Convert a std::string to char* in C++? In C++, strings are the textual data that is represented in two ways: std::string which is an object, and char* is a pointer to a character. In this article, we will learn how to convert a std::string to char* in C++. Example Input:string myString = "GeeksforGeeks";Output:char * myString = "Geeksfor 1 min read How to Compare Two Substrings in a Character Array in C++? In C++, character arrays are used to store a sequence of characters also known as strings. A Substring is a continuous sequence of characters within a string. In this article, we will learn how we can compare two substrings in a character array in C++. Examples: Input: string: "Hello World" Substrin 2 min read How to Split a String into an Array in C++? In C++, splitting a string into an array of substrings means we have to parse the given string based on a delimiter and store each substring in an array. In this article, we will learn how to split a string into an array of substrings in C++. Example: Input: str= âHello, I am Geek from geeksforgeeks 2 min read How to Extract a Substring from a Character Array in C++? In C++, character arrays are used to store sequences of characters also known as strings. A substring is a part of a string that consists of a continuous sequence of characters from the string. In this article, we will learn how to extract a substring from a character array in C++. Extract a Substri 2 min read Like