![]() |
In C++, Char array and std::string both are used to store a sequence of characters to represent textual data. In this article, we will learn how to check if a substring exists within a char array in C++. Example Input: charArray[]= "Hello, Geek" subString="Geek" Output: Geek substring is found in char array: Hello, Geek! Search for a Substring in Char ArrayThe C++ STL provides the std::find() function to search for a given substring in a range of values.
C++ Program to Search for a Substring in Char ArrayC++
Output
Geek substring is found in char array: Hello, Geek! Time Complexity: O(N * M), where N is the size of the char array and M is the size of the substring. We can also use strstr() function to check if a substring exists in a char array or not. |
Reffered: https://www.geeksforgeeks.org
C++ |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 10 |