{"id":104377,"date":"2020-02-27T12:50:01","date_gmt":"2020-02-27T12:50:01","guid":{"rendered":"https:\/\/www.softwaretestinghelp.com\/?page_id=104377"},"modified":"2025-04-01T08:13:45","modified_gmt":"2025-04-01T08:13:45","slug":"general-strings-functions-cpp","status":"publish","type":"page","link":"https:\/\/www.softwaretestinghelp.com\/general-strings-functions-cpp\/","title":{"rendered":"String Functions In C++: getline, substring, string length &#038; More"},"content":{"rendered":"\n<p><strong>In this Tutorial, we will Discuss some of the Popular String Functions in C++ such as getline substring, string length, string find, split string, etc.:<\/strong><\/p>\n\n\n\n<p>C++ has a string class that is used for a sequence of characters which is also known as strings. This class is <strong>std:: string<\/strong>. This class stores the strings as a sequence of character bytes and provides functions that allow us to manipulate, access, and read the strings as well as access and manipulate single characters.<\/p>\n\n\n\n<p>=> <a href=\"https:\/\/www.softwaretestinghelp.com\/cpp-tutorials\/\"><strong>Visit Here For The Complete C++ Course From Experts.<\/strong><\/a><em><\/wp-block><\/em><\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2019\/09\/C-Strings_-General-Functions.png\"><img decoding=\"async\" width=\"650\" height=\"366\" src=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2019\/09\/C-Strings_-General-Functions.png\" alt=\"C++ Strings_ General Functions\" class=\"wp-image-104884\" srcset=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2019\/09\/C-Strings_-General-Functions.png 650w, https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2019\/09\/C-Strings_-General-Functions-300x169.png 300w\" sizes=\"(max-width: 650px) 100vw, 650px\" \/><\/a><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">C++ String Functions<\/h2>\n\n\n\n<p>C++ string is a sequence of characters. When we define strings in C++, we use a string<br>keyword that is nothing but std::string class. This string class supports various functions from reading a string, manipulating, accessing a string, etc. that perform different operations on string objects. Some frequently used functions are listed below-<\/p>\n\n\n\n<div id=\"tablepress-987-scroll-wrapper\" class=\"tablepress-scroll-wrapper\">\n<table id=\"tablepress-987\" class=\"tablepress tablepress-id-987 tablepress-responsive\">\n<thead>\n<tr class=\"row-1\">\n\t<th class=\"column-1\">No<\/th><th class=\"column-2\">String functions<\/th><th class=\"column-3\">Description<\/th>\n<\/tr>\n<\/thead>\n<tbody class=\"row-striping row-hover\">\n<tr class=\"row-2\">\n\t<td class=\"column-1\">1<\/td><td class=\"column-2\">getline<\/td><td class=\"column-3\">Gets the line from stream to string<\/td>\n<\/tr>\n<tr class=\"row-3\">\n\t<td class=\"column-1\">2<\/td><td class=\"column-2\">substr<\/td><td class=\"column-3\">Get a substring of a given string<\/td>\n<\/tr>\n<tr class=\"row-4\">\n\t<td class=\"column-1\">4<\/td><td class=\"column-2\">Length, strlen<\/td><td class=\"column-3\">Get length of the string<\/td>\n<\/tr>\n<tr class=\"row-5\">\n\t<td class=\"column-1\">5<\/td><td class=\"column-2\">Find<\/td><td class=\"column-3\">Find content in string<\/td>\n<\/tr>\n<tr class=\"row-6\">\n\t<td class=\"column-1\">6<\/td><td class=\"column-2\">Strtok, substr with delimiter<\/td><td class=\"column-3\">Split string in tokens<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<!-- #tablepress-987 from cache -->\n\n\n<h3 class=\"wp-block-heading\"><span style=\"color: #ff6600;\">getline C++<\/span><\/h3>\n\n\n\n<p><strong> Function Prototype: <\/strong>istream&amp; getline(istream&amp; is, string&amp; str)<\/p>\n\n\n\n<p><strong> Parameter(s): <\/strong>is =&gt; istream object from which the characters are extracted.<\/p>\n\n\n\n<p>str=&gt; String object that is used to store extracted character.<\/p>\n\n\n\n<p><strong> Return Value: <\/strong>Return value is the same as istream is. Internally, the execution of the getline sets certain internal flags as follows.<\/p>\n\n\n\n<div id=\"tablepress-989-scroll-wrapper\" class=\"tablepress-scroll-wrapper\">\n<table id=\"tablepress-989\" class=\"tablepress tablepress-id-989 tablepress-responsive\">\n<thead>\n<tr class=\"row-1\">\n\t<th class=\"column-1\">flag<\/th><th class=\"column-2\">Error description<\/th>\n<\/tr>\n<\/thead>\n<tbody class=\"row-striping row-hover\">\n<tr class=\"row-2\">\n\t<td class=\"column-1\">eofbit<\/td><td class=\"column-2\">End of the character source reached<\/td>\n<\/tr>\n<tr class=\"row-3\">\n\t<td class=\"column-1\">failbit<\/td><td class=\"column-2\">Input cannot be interpreted as a valid textual representation of the object of this type<\/td>\n<\/tr>\n<tr class=\"row-4\">\n\t<td class=\"column-1\">badbit<\/td><td class=\"column-2\">Any other error except the above two<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<!-- #tablepress-989 from cache -->\n\n\n<p><strong>Description: <\/strong>getline is a standard library function. This function is used to read a line or string from a standard input stream like istream. The lines or strings are read until \u201c\\n\u201d which is considered as delimitation character is encountered.<\/p>\n\n\n\n<p>As a different version of getline, a third parameter \u201cchar delim\u201d can be specified. This is a delimiter character specified explicitly. In this function, a line of text or string will be read until the delimiter character specified is encountered.<\/p>\n\n\n\n<p><strong>Given below is a simple example to demonstrate usage of getline.<\/strong><\/p>\n\n\n\n<p><span style=\"text-decoration: underline;\"><strong> Example:<\/strong><\/span><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\n#include &lt;iostream&gt;\n#include &lt;string&gt;\nusing namespace std;\n \nint main()\n{\n    string mystr;\n    cout&lt;&lt;&quot;Enter the input string:&quot;&lt;&lt;endl;\n    getline(cin,mystr);\n    cout&lt;&lt;&quot;You entered: &quot;&lt;&lt;mystr;\n     \n}\n     \n}\n<\/pre><\/div>\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<p>Enter the input string:<br>C++ tutorials<br>You entered: C++ tutorials<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2019\/09\/1-3.png\"><img decoding=\"async\" width=\"242\" height=\"79\" src=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2019\/09\/1-3.png\" alt=\"getline\" class=\"wp-image-104551\"\/><\/a><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>In the above example, we read an input string using the getline function. Note that the strings or text entered is read into string object mystr until \u2018\\n\u2019 is encountered.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span style=\"color: #ff6600;\">C++ Substr<\/span><\/h3>\n\n\n\n<p><strong> Function Prototype: <\/strong>string substr(size_t startpos, size_t endpos)<\/p>\n\n\n\n<p><strong> Parameter(s): <\/strong>startpos=&gt; Starting position from where the substring is to be extracted.<\/p>\n\n\n\n<p>endpos=&gt; End position of substring.<\/p>\n\n\n\n<p><strong> Return Value: <\/strong>Returns a string that is a substring of the parent string.<\/p>\n\n\n\n<p><strong> Description: <\/strong>This function returns a substring of a given string. The function takes the start and end positions as parameters and then returns the sequence of character between these positions.<\/p>\n\n\n\n<p><span style=\"text-decoration: underline;\"><strong>Example:<\/strong><\/span><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n#include &lt;iostream&gt;\n#include &lt;string&gt;\nusing namespace std;\n \nint main()\n{\n    string mystr = &quot;SoftwareTestingHelp&quot;;\n    string mysub = mystr.substr(0,8);\n    cout&lt;&lt;&quot;Input string : &quot;&lt;&lt;mystr&lt;&lt;endl;\n    cout&lt;&lt;&quot;Substring(0,8) : &quot;&lt;&lt;mysub&lt;&lt;endl;\n     \n}\n<\/pre><\/div>\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<p>Input string : SoftwareTestingHelp<br>Substring(0,8) : Software<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2019\/09\/2-3.png\"><img decoding=\"async\" width=\"351\" height=\"45\" src=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2019\/09\/2-3.png\" alt=\"Substr\" class=\"wp-image-104552\" srcset=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2019\/09\/2-3.png 351w, https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2019\/09\/2-3-300x38.png 300w\" sizes=\"(max-width: 351px) 100vw, 351px\" \/><\/a><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span style=\"color: #ff6600;\">C++ Length<\/span><\/h3>\n\n\n\n<p>The length of the string is the number of characters present in the string. The std::string object representation of strings in C++ uses the length () functions to return the length of the string.<\/p>\n\n\n\n<p>Apart from this, we also have a size method that returns the size of the string. We have used the size method in the example shown below for the length () function. Another function that returns the length of the string is \u2018strlen\u2019. This function returns the length of the string denoted by a character array.<\/p>\n\n\n\n<p>We will see both the functions one by one with examples.<\/p>\n\n\n\n<p><span style=\"color: #000000;\"><strong> length()<\/strong><\/span><\/p>\n\n\n\n<p><strong> Function Prototype: <\/strong>size_t length ()<\/p>\n\n\n\n<p><strong> Parameter(s): <\/strong>Invoked by the string whose length is to be found out.<\/p>\n\n\n\n<p><strong> Return Value: <\/strong>Returns a size_t type parameter which is the length of the string.<\/p>\n\n\n\n<p><strong> Description: <\/strong>This function finds the length of the string object by which it is invoked.<\/p>\n\n\n\n<p><span style=\"text-decoration: underline;\"><strong>Example:<\/strong><\/span><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n#include &lt;iostream&gt;\n#include &lt;cstring&gt;\nusing namespace std;\n \nint main()\n{\n    string mystr = &quot;SoftwareTestingHelp&quot;;\n    cout&lt;&lt;&quot;Input string : &quot;&lt;&lt;mystr&lt;&lt;endl;\n    cout&lt;&lt;&quot;The length of the string (with length method )is: &quot;&lt;&lt;mystr.length()&lt;&lt;endl;\n     \n    cout&lt;&lt;&quot;The size of the string (with size method )is: &quot;&lt;&lt;mystr.size()&lt;&lt;endl;\n}\n<\/pre><\/div>\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<p>Input string : SoftwareTestingHelp<br>The length of the string (with length method )is: 19<br>The size of the string (with size method )is: 19<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2019\/09\/3-3.png\"><img decoding=\"async\" width=\"472\" height=\"79\" src=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2019\/09\/3-3.png\" alt=\"Length\" class=\"wp-image-104553\" srcset=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2019\/09\/3-3.png 472w, https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2019\/09\/3-3-300x50.png 300w\" sizes=\"(max-width: 472px) 100vw, 472px\" \/><\/a><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>In the above program, we use the length as well as size functions of the std::string that returns the length and size of the string object respectively. As length and size return the number of characters in the string, we get the same output.<\/p>\n\n\n\n<p><span style=\"color: #000000;\"><strong> strlen()<\/strong><\/span><\/p>\n\n\n\n<p><strong>Function Prototype: <\/strong>size_t strlen (const char* str);<\/p>\n\n\n\n<p><strong> Parameter(s): <\/strong>str=&gt; Pointer to a null-terminated string whose length is to be found out.<\/p>\n\n\n\n<p><strong> Return Value: R<\/strong>eturns size_t value denoting the length of the string str.<\/p>\n\n\n\n<p><strong>Description: <\/strong>strlen() function returns the length of the null-terminated string. The string that is taken as a parameter by the strlen function is a null-terminated character array.<\/p>\n\n\n\n<p><span style=\"text-decoration: underline;\"><strong>Example:<\/strong><\/span><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n#include &lt;cstring&gt;\n#include &lt;iostream&gt;\nusing namespace std;\nint main()\n \n{\n \n    char mystr1&#x5B;] = &quot;This a our first string&quot;;\n    char mystr2&#x5B;] = &quot;This is our second string&quot;; \n    int len_mystr1 = strlen(mystr1);\n    int len_mystr2 = strlen(mystr2);\n    cout &lt;&lt; &quot;Length of mystr1 = &quot; &lt;&lt; len_mystr1 &lt;&lt; endl;\n    cout &lt;&lt; &quot;Length of mystr2 = &quot; &lt;&lt; len_mystr2 &lt;&lt; endl;\n    if (len_mystr1 &gt; len_mystr2)\n        cout &lt;&lt; &quot;mystr1 is longer than mystr2&quot;;\n   else if (len_mystr1 &lt; len_mystr2)\n        cout &lt;&lt; &quot;mystr2 is longer than mystr1&quot;;\n    else\n        cout &lt;&lt; &quot;mystr1 and mystr2 are equal in length&quot;;\n    return 0;\n}\n<\/pre><\/div>\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<p>Length of mystr1 = 23<br>Length of mystr2 = 25<br>mystr2 is longer than mystr1<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2019\/09\/4-3.png\"><img decoding=\"async\" width=\"351\" height=\"78\" src=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2019\/09\/4-3.png\" alt=\"strlen\" class=\"wp-image-104554\" srcset=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2019\/09\/4-3.png 351w, https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2019\/09\/4-3-300x67.png 300w\" sizes=\"(max-width: 351px) 100vw, 351px\" \/><\/a><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>In the above program, we have defined two different strings and we find their individual length using the strlen function. Then we compare the length of the two strings and determine if the strings are equal or unequal.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span style=\"color: #ff6600;\">C++ Find<\/span><\/h3>\n\n\n\n<p><strong> Function Prototype: <\/strong>size_t find(string mysub)<\/p>\n\n\n\n<p><strong> Parameter(s): <\/strong>mysub=&gt; String object to find inside the parent string.<\/p>\n\n\n\n<p><strong> Return Value: <\/strong>size_t=&gt; First position of the substring in the parent string<\/p>\n\n\n\n<p><strong> Description: <\/strong>The find function of the string is used to find the position of the substring in the parent string. This function is invoked by the parent string and a substring whose position is to be found is passed as a parameter. If the substring is not present, an empty position is returned.<\/p>\n\n\n\n<p><span style=\"text-decoration: underline;\"><strong> Example:<\/strong><\/span><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n#include &lt;iostream&gt;\n#include &lt;cstring&gt;\nusing namespace std;\n \nint main()\n{\n    string mystr = &quot;SoftwareTestingHelp&quot;;\n    string mysub = &quot;Test&quot;;\n     \n    size_t pos = mystr.find(mysub);\n     \n   if (pos != string::npos) \n        cout &lt;&lt; &quot;First occurrence of string &quot;&lt;&lt;mysub&lt;&lt;&quot;:&quot; &lt;&lt; pos &lt;&lt; endl; \n   \n    mysub = &quot;Help&quot;;\n     \n    pos = mystr.find(mysub);\n    if (pos != string::npos) \n       cout &lt;&lt; &quot;First occurrence of string &quot;&lt;&lt;mysub&lt;&lt;&quot;:&quot; &lt;&lt; pos &lt;&lt; endl; \n \n}\n<\/pre><\/div>\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<p>First occurrence of string Test:8<br>First occurrence of string Help:15<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2019\/09\/5-2.png\"><img decoding=\"async\" width=\"318\" height=\"46\" src=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2019\/09\/5-2.png\" alt=\"Find\" class=\"wp-image-104555\" srcset=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2019\/09\/5-2.png 318w, https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2019\/09\/5-2-300x43.png 300w\" sizes=\"(max-width: 318px) 100vw, 318px\" \/><\/a><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>This program defines a string as \u201cSoftwareTestingHelp\u201d. Using the find function we find the first occurrence of the string \u201cTest\u201d in the parent string. Next, we find the occurrence of the \u201cHelp\u201d string. The output is the position of the occurrence of the searched string.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span style=\"color: #ff6600;\">Split String<\/span><\/h3>\n\n\n\n<p>Splitting a string using a delimiter or a token is a useful operation. In C++, as we have more than one representation of strings, we can use different approaches to splitting a string. Here, we will discuss two approaches to splitting a string.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Splitting std:: string Object<\/h4>\n\n\n\n<p>The easiest approach to split a string object is to use the \u2018substr\u2019 function on the object and provide the delimiter as the end position so that we get the substring. In this way, we can split the string on delimiter until we have traversed the entire string.<\/p>\n\n\n\n<p><strong>Let&#8217;s see the example below that first finds the position of the delimiter using the \u2018find\u2019 function and then finds the substring and finally outputs each of the tokens.<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n#include &lt;iostream&gt;\n#include &lt;string&gt;\nusing namespace std;\n \nint main()\n{\n     \n    string mystr = &quot;This_is_software_testing_help&quot;;\n    string delimiter = &quot;_&quot;;\n \n    size_t pos = 0;\n    string token;\n    while ((pos = mystr.find(delimiter)) != std::string::npos) \n    {\n        token = mystr.substr(0, pos);\n        cout &lt;&lt; token &lt;&lt; endl;\n        mystr.erase(0, pos + delimiter.length());\n    }\n    cout &lt;&lt; mystr&lt;&lt; endl;\n}\n<\/pre><\/div>\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<p>This<br>is<br>software<br>testing<br>help<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2019\/09\/6-2.png\"><img decoding=\"async\" width=\"150\" height=\"141\" src=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2019\/09\/6-2.png\" alt=\"Splitting std:: string object\" class=\"wp-image-104556\"\/><\/a><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>As shown in the above program, we specify a delimiter that will be used to split the given string. In a loop, we repeatedly find the occurrence of delimiter using the find function and pass it to the substr function and retrieve the substring. Then each of these tokens obtained is displayed as the output.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Splitting Character Array Using strtok Function<\/h4>\n\n\n\n<p>Another way of tokenizing a string (splitting string using a delimiter) is by using the \u2018strtok\u2019 function. We will discuss the specifics of the \u2018strtok\u2019 function below.<\/p>\n\n\n\n<p><strong> Function Prototype: <\/strong>char* strtok(char str [], const char *delim)<\/p>\n\n\n\n<p><strong> Parameter(s): <\/strong>str[] =&gt; String to be split.<\/p>\n\n\n\n<p>Delim =&gt; Delimiter on which the string is to be split.<\/p>\n\n\n\n<p><strong> Return Value: <\/strong>Returns the next token after splitting the parent string.<\/p>\n\n\n\n<p><strong> Description: <\/strong>The strtok function splits the given string into tokens on given delimiters. This function needs to be called in a loop so that we get all the tokens for a given string. When there are no more tokens left, the function returns null.<\/p>\n\n\n\n<p><span style=\"text-decoration: underline;\"><strong> Example:<\/strong><\/span><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n#include &lt;cstring&gt;\n#include &lt;iostream&gt;\nusing namespace std;\nint main()\n{\n    char mystr&#x5B;] = &quot;This_is_software_testing_help&quot;; \n   \n    char *token = strtok(mystr, &quot;_&quot;); \n   \n   while (token != NULL) \n    { \n        cout&lt;&lt;token&lt;&lt;endl; \n        token = strtok(NULL, &quot;_&quot;); \n    } \n   \n    return 0; \n}\n<\/pre><\/div>\n\n\n<p><strong> Output:<\/strong><\/p>\n\n\n\n<p>This<br>is<br>software<br>testing<br>help<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2019\/09\/7-1.png\"><img decoding=\"async\" width=\"132\" height=\"142\" src=\"https:\/\/www.softwaretestinghelp.com\/wp-content\/qa\/uploads\/2019\/09\/7-1.png\" alt=\"strtok function\" class=\"wp-image-104557\"\/><\/a><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Note that, in this program, we use the strtok function which takes a string and delimiter as the arguments. Then it splits the string into the token, based on the delimiter specified and displays the individual tokens.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>We have seen some of the generally important functions used for C++ strings in this tutorial.<\/p>\n\n\n\n<p>We discussed the functions to read an input string, find a string, substring of the parent string, length of the string, splitting a string, etc. along with their variations. These functions help us to read and manipulate strings efficiently.<\/p>\n\n\n\n<p>In our next tutorial, we will see some of the conversion functions used with C++ string in detail.<\/p>\n\n\n\n<p><strong>=&gt; <a href=\"https:\/\/www.softwaretestinghelp.com\/cpp-tutorials\/\">Visit Here To See The Entire C++ Training Series For All.<\/a><\/strong><\/p>\n\r\n\t\t\t<div id=\"daexthefup-container\"\r\n\t\t\t\tclass=\"daexthefup-container daexthefup-layout-stacked daexthefup-alignment-center\"\r\n\t\t\t\tdata-post-id=\"104377\">\r\n\r\n\t\t\t\t<div class=\"daexthefup-feedback\">\r\n\t\t\t\t\t<div class=\"daexthefup-text\">\r\n\t\t\t\t\t\t<h3 class=\"daexthefup-title\">Was this helpful?<\/h3>\r\n\t\t\t\t\t<\/div>\r\n\t\t\t\t\t<div class=\"daexthefup-buttons-container\">\r\n\t\t\t\t\t\t<div class=\"daexthefup-buttons\">\r\n\t\t\t\t\t\t\t\r\n\t\t\t<div class=\"daexthefup-yes daexthefup-button daexthefup-button-type-icon\" data-value=\"1\">\r\n\t\t\t\t\r\n                <svg>\r\n                    <defs>\r\n                        <style>.thumb-up-cls-1{fill:#c9c9c9;}.thumb-up-cls-2{fill:#e1e1e1;}.thumb-up-cls-3{fill:#676767;}<\/style>\r\n                    <\/defs>\r\n                    <g id=\"thumb_up\">\r\n                        <path class=\"thumb-up-cls-2 daexthefup-icon-circle\" d=\"m24,3c11.58,0,21,9.42,21,21s-9.42,21-21,21S3,35.58,3,24,12.42,3,24,3m0-1C11.85,2,2,11.85,2,24s9.85,22,22,22,22-9.85,22-22S36.15,2,24,2h0Z\" \/>\r\n                        <g>\r\n                            <rect class=\"thumb-up-cls-3 daexthefup-icon-secondary-color\" x=\"10\" y=\"20\" width=\"6\" height=\"15\" rx=\"1.5\" ry=\"1.5\" \/>\r\n                            <path class=\"thumb-up-cls-1 daexthefup-icon-primary-color\" d=\"m30.57,9.06l-.49-.1c-.81-.17-1.61.35-1.78,1.16l-5.3,11.74c-.17.81,3.16,1.61,3.97,1.78l1.96.41c.81.17,1.61-.35,1.78-1.16l2.18-10.27c.34-1.61-.7-3.21-2.31-3.56Z\" \/>\r\n                            <path class=\"thumb-up-cls-1 daexthefup-icon-primary-color\" d=\"m38.17,20h-18.67c-.83,0-1.5.67-1.5,1.5v12c0,.83.67,1.5,1.5,1.5h16.27c.71,0,1.33-.5,1.47-1.21l2.4-12c.19-.93-.53-1.8-1.47-1.8Z\" \/>\r\n                        <\/g>\r\n                    <\/g>\r\n                <\/svg>\t\t\t<\/div>\r\n\r\n\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t<div class=\"daexthefup-no daexthefup-button daexthefup-button-type-icon\" data-value=\"0\">\r\n\t\t\t\t\r\n                <svg>\r\n                    <defs>\r\n                        <style>.thumb-down-cls-1{fill:#c9c9c9;}.thumb-down-cls-2{fill:#e1e1e1;}.thumb-down-cls-3{fill:#676767;}<\/style>\r\n                    <\/defs>\r\n                    <g id=\"thumb_down\">\r\n                        <path class=\"thumb-down-cls-2 daexthefup-icon-circle\" d=\"m24,3c11.58,0,21,9.42,21,21s-9.42,21-21,21S3,35.58,3,24,12.42,3,24,3m0-1C11.85,2,2,11.85,2,24s9.85,22,22,22,22-9.85,22-22S36.15,2,24,2h0Z\" \/>\r\n                        <g>\r\n                            <rect class=\"thumb-down-cls-3 daexthefup-icon-secondary-color\" x=\"10\" y=\"13\" width=\"6\" height=\"15\" rx=\"1.5\" ry=\"1.5\" \/>\r\n                            <path class=\"thumb-down-cls-1 daexthefup-icon-primary-color\" d=\"m30.57,38.94l-.49.1c-.81.17-1.61-.35-1.78-1.16l-5.3-11.74c-.17-.81,3.16-1.61,3.97-1.78l1.96-.41c.81-.17,1.61.35,1.78,1.16l2.18,10.27c.34,1.61-.7,3.21-2.31,3.56Z\" \/>\r\n                            <path class=\"thumb-down-cls-1 daexthefup-icon-primary-color\" d=\"m38.17,28h-18.67c-.83,0-1.5-.67-1.5-1.5v-12c0-.83.67-1.5,1.5-1.5h16.27c.71,0,1.33.5,1.47,1.21l2.4,12c.19.93-.53,1.8-1.47,1.8Z\" \/>\r\n                        <\/g>\r\n                    <\/g>\r\n                <\/svg>\t\t\t<\/div>\r\n\r\n\t\t\t\t\t\t\t\t\t<\/div>\r\n\t\t\t\t\t<\/div>\r\n\t\t\t\t<\/div>\r\n\r\n\t\t\t\t<div class=\"daexthefup-comment\">\r\n\t\t\t\t\t<div class=\"daexthefup-comment-top-container\">\r\n\t\t\t\t\t\t<label id=\"daexthefup-comment-label\" class=\"daexthefup-comment-label\"><\/label>\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t<div class=\"daexthefup-comment-character-counter-container\">\r\n\t\t\t\t\t\t\t\t<div id=\"daexthefup-comment-character-counter-number\"\r\n\t\t\t\t\t\t\t\t\tclass=\"daexthefup-comment-character-counter-number\"><\/div>\r\n\t\t\t\t\t\t\t\t<div class=\"daexthefup-comment-character-counter-text\"><\/div>\r\n\t\t\t\t\t\t\t<\/div>\r\n\t\t\t\t\t\t\t\t\t\t\t<\/div>\r\n\t\t\t\t\t<textarea id=\"daexthefup-comment-textarea\" class=\"daexthefup-comment-textarea\"\r\n\t\t\t\t\t\t\t\tplaceholder=\"Type your message\"\r\n\t\t\t\t\t\t\t\tmaxlength=\"\r\n\t\t\t\t\t\t\t\t400\t\t\t\t\t\t\t\t\t\"><\/textarea>\r\n\t\t\t\t\t<div class=\"daexthefup-comment-buttons-container\">\r\n\t\t\t\t\t\t<button class=\"daexthefup-comment-submit daexthefup-button\">Submit<\/button>\r\n\t\t\t\t\t\t<button class=\"daexthefup-comment-cancel daexthefup-button\">Cancel<\/button>\r\n\t\t\t\t\t<\/div>\r\n\t\t\t\t<\/div>\r\n\r\n\t\t\t\t<div class=\"daexthefup-successful-submission-text\">Thanks for your feedback!<\/div>\r\n\r\n\t\t\t<\/div>\r\n\r\n\t\t\t","protected":false},"excerpt":{"rendered":"<p>In this Tutorial, we will Discuss some of the Popular String Functions in C++ such as getline substring, string length, string find, split string, etc.: C++ has a string class that is used for a sequence of characters which is also known as strings. This class is std:: string. This &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"String Functions In C++: getline, substring, string length &#038; More\" class=\"read-more button\" href=\"https:\/\/www.softwaretestinghelp.com\/general-strings-functions-cpp\/#more-104377\" aria-label=\"Read more about String Functions In C++: getline, substring, string length &#038; More\">Read more<\/a><\/p>\n","protected":false},"author":9,"featured_media":104884,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_acf_changed":false,"_helpful_pro_status":1,"footnotes":""},"categories":[403],"tags":[],"class_list":{"0":"post-104377","1":"page","2":"type-page","3":"status-publish","4":"has-post-thumbnail","6":"category-cpp"},"acf":[],"_links":{"self":[{"href":"https:\/\/www.softwaretestinghelp.com\/wp-json\/wp\/v2\/pages\/104377","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.softwaretestinghelp.com\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.softwaretestinghelp.com\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.softwaretestinghelp.com\/wp-json\/wp\/v2\/users\/9"}],"replies":[{"embeddable":true,"href":"https:\/\/www.softwaretestinghelp.com\/wp-json\/wp\/v2\/comments?post=104377"}],"version-history":[{"count":0,"href":"https:\/\/www.softwaretestinghelp.com\/wp-json\/wp\/v2\/pages\/104377\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.softwaretestinghelp.com\/wp-json\/wp\/v2\/media\/104884"}],"wp:attachment":[{"href":"https:\/\/www.softwaretestinghelp.com\/wp-json\/wp\/v2\/media?parent=104377"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.softwaretestinghelp.com\/wp-json\/wp\/v2\/categories?post=104377"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.softwaretestinghelp.com\/wp-json\/wp\/v2\/tags?post=104377"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}