{"id":8520,"date":"2023-12-25T20:43:09","date_gmt":"2023-12-25T20:43:09","guid":{"rendered":"https:\/\/hatchjs.com\/?p=8520"},"modified":"2024-01-05T16:02:48","modified_gmt":"2024-01-05T16:02:48","slug":"looping-through-string-c","status":"publish","type":"post","link":"https:\/\/hatchjs.com\/looping-through-string-c\/","title":{"rendered":"How to Loop Through a String in C++"},"content":{"rendered":"<p><b>Looping Through Strings in C++<\/b><\/p>\n<p>Strings are a fundamental data type in C++, and they&#8217;re used to store sequences of characters. Looping through a string is a common task, and there are a few different ways to do it. In this article, we&#8217;ll take a look at the three most common methods for looping through strings in C++:<\/p>\n<ul>\n<li>Using the `for` loop<\/li>\n<li>Using the `while` loop<\/li>\n<li>Using the `do-while` loop<\/li>\n<\/ul>\n<p>We&#8217;ll also discuss the pros and cons of each method, and we&#8217;ll provide some examples of how to use them. By the end of this article, you&#8217;ll be able to choose the best method for looping through strings in your C++ programs.<\/p>\n<table>\n<tr>\n<th>Keyword<\/th>\n<th>Description<\/th>\n<th>Example<\/th>\n<\/tr>\n<tr>\n<td>Looping through string<\/td>\n<td>The process of iterating over the characters in a string<\/td>\n<td>\ninclude <iostream><\/p>\n<p>using namespace std;<\/p>\n<p>int main() {<br \/>\n  \/\/ Define a string<br \/>\n  string str = &#8220;Hello World!&#8221;;<\/p>\n<p>  \/\/ Loop through the string using a for loop<br \/>\n  for (int i = 0; i < str.length(); i++) {\n    cout << str[i] << endl;\n  }\n\n  \/\/ Loop through the string using a while loop\n  int i = 0;\n  while (i < str.length()) {\n    cout << str[i] << endl;\n    i++;\n  }\n\n  \/\/ Loop through the string using a do-while loop\n  i = 0;\n  do {\n    cout << str[i] << endl;\n    i++;\n  } while (i < str.length());\n\n  return 0;\n}\n\n<\/table>\n<\/p>\n<p>In C++, a string is a sequence of characters. It is one of the most basic data types in C++, and it is used to store text data. Strings can be created using the `string` keyword, and they can be manipulated using a variety of methods.<\/p>\n<p>One of the most common tasks that you will need to do with strings is to loop through them. This can be done using a variety of different methods, each of which has its own advantages and disadvantages.<\/p>\n<p>In this tutorial, we will discuss the different ways to loop through a string in C++, and we will show you how to access individual characters in a string. We will also provide some code examples to help you understand how to use these methods.<\/p>\n<p>Different ways to loop through a string in C++<\/p>\n<p>There are four different ways to loop through a string in C++:<\/p>\n<ul>\n<li>Using a for loop<\/li>\n<li>Using an while loop<\/li>\n<li>Using a do-while loop<\/li>\n<li>Using the range-based for loop<\/li>\n<\/ul>\n<p>We will discuss each of these methods in detail below.<\/p>\n<p>Using a for loop<\/p>\n<p>The most common way to loop through a string in C++ is to use a for loop. A for loop allows you to iterate over a sequence of elements, and it is a very versatile tool.<\/p>\n<p>To loop through a string using a for loop, you can use the following syntax:<\/p>\n<p>c++<br \/>\nfor (int i = 0; i < str.length(); i++) {\n  \/\/ Do something with the character at index i\n}\n\n\nIn this example, the `for` loop iterates over the characters in the string `str`. The variable `i` is used to keep track of the current index, and the expression `str.length()` returns the length of the string.\n\nUsing an while loop\n\nAnother way to loop through a string in C++ is to use a while loop. A while loop allows you to iterate over a sequence of elements as long as a certain condition is met.\n\nTo loop through a string using a while loop, you can use the following syntax:\n\nc++\nint i = 0;\nwhile (i < str.length()) {\n  \/\/ Do something with the character at index i\n  i++;\n}\n\n\nIn this example, the `while` loop iterates over the characters in the string `str` as long as the variable `i` is less than the length of the string.\n\nUsing a do-while loop\n\nA do-while loop is similar to a while loop, except that the condition is checked at the end of the loop instead of the beginning. This means that a do-while loop will always execute at least once, even if the condition is not met.\n\nTo loop through a string using a do-while loop, you can use the following syntax:\n\nc++\nint i = 0;\ndo {\n  \/\/ Do something with the character at index i\n  i++;\n} while (i < str.length());\n\n\nIn this example, the `do-while` loop iterates over the characters in the string `str` until the variable `i` is greater than the length of the string.\n\nUsing the range-based for loop\n\nThe range-based for loop is a new feature in C++11 that makes it easier to iterate over a sequence of elements. To loop through a string using a range-based for loop, you can use the following syntax:\n\nc++\nfor (char c : str) {\n  \/\/ Do something with the character c\n}\n\n\nIn this example, the `range-based for` loop iterates over the characters in the string `str`. The variable `c` is used to store each character in the string.\n\nHow to access individual characters in a string in C++\n\nThere are three different ways to access individual characters in a string in C++:\n\n\n\n<ul>\n<li>Using the subscript operator<\/li>\n<li>Using the at() function<\/li>\n<li>Using the [] operator<\/li>\n<\/ul>\n<p>We will discuss each of these methods in detail below.<\/p>\n<p>Using the subscript operator<\/p>\n<p>The subscript operator ([]) can be used to access individual characters in a string. The syntax for using the subscript operator is as follows:<\/p>\n<p>c++<br \/>\nstr[index]<\/p>\n<p>In this expression, `str` is the string, and `index` is the index of the character that you want to access. The index starts at 0, so the first character in the string is at index 0.<\/p>\n<p>For example, the following code will print the first character in the string `str`:<\/p>\n<p>c++<br \/>\ncout << str[0];\n\n\nUsing the at()\n\n<\/p>\n<\/p>\n<p>How to loop through a string in C++<\/p>\n<p>In C++, you can loop through a string using the following methods:<\/p>\n<ul>\n<li>Using the `for` loop<\/li>\n<li>Using the `while` loop<\/li>\n<li>Using the `do-while` loop<\/li>\n<\/ul>\n<p>Using the `for` loop<\/p>\n<p>To loop through a string using the `for` loop, you can use the following syntax:<\/p>\n<p>c++<br \/>\nfor (int i = 0; i < string.length(); i++) {\n  \/\/ Do something with the character at index i\n}\n\n\nIn this example, the `for` loop iterates through the string from index 0 to the length of the string minus 1. At each iteration, the value of `i` is incremented by 1.\n\nYou can also use the `for` loop to loop through a string backwards. To do this, you can use the following syntax:\n\nc++\nfor (int i = string.length() - 1; i >= 0; i&#8211;) {<br \/>\n  \/\/ Do something with the character at index i<br \/>\n}<\/p>\n<p>Using the `while` loop<\/p>\n<p>To loop through a string using the `while` loop, you can use the following syntax:<\/p>\n<p>c++<br \/>\nint i = 0;<br \/>\nwhile (i < string.length()) {\n  \/\/ Do something with the character at index i\n  i++;\n}\n\n\nIn this example, the `while` loop iterates through the string as long as the value of `i` is less than the length of the string. At each iteration, the value of `i` is incremented by 1.\n\nUsing the `do-while` loop\n\nTo loop through a string using the `do-while` loop, you can use the following syntax:\n\nc++\nint i = 0;\ndo {\n  \/\/ Do something with the character at index i\n  i++;\n} while (i < string.length());\n\n\nIn this example, the `do-while` loop iterates through the string once, even if the value of `i` is less than the length of the string. At each iteration, the value of `i` is incremented by 1.\n\nHow to find the length of a string in C++\n\nThere are three ways to find the length of a string in C++:\n\n\n\n<ul>\n<li>Using the `size()` function<\/li>\n<li>Using the `length()` function<\/li>\n<li>Using the `std::strlen()` function<\/li>\n<\/ul>\n<p>Using the `size()` function<\/p>\n<p>The `size()` function returns the number of characters in a string. To use the `size()` function, you can use the following syntax:<\/p>\n<p>c++<br \/>\nint length = string.size();<\/p>\n<p>In this example, the `length` variable will be assigned the number of characters in the `string` variable.<\/p>\n<p>Using the `length()` function<\/p>\n<p>The `length()` function is a legacy function that is still supported in C++. However, it is not recommended to use the `length()` function because it is not as portable as the `size()` function.<\/p>\n<p>To use the `length()` function, you can use the following syntax:<\/p>\n<p>c++<br \/>\nint length = string.length();<\/p>\n<p>In this example, the `length` variable will be assigned the number of characters in the `string` variable.<\/p>\n<p>Using the `std::strlen()` function<\/p>\n<p>The `std::strlen()` function is a standard library function that returns the number of characters in a string. To use the `std::strlen()` function, you can use the following syntax:<\/p>\n<p>c++<br \/>\nint length = std::strlen(string);<\/p>\n<p>In this example, the `length` variable will be assigned the number of characters in the `string` variable.<\/p>\n<p>How to compare strings in C++<\/p>\n<p>There are six ways to compare strings in C++:<\/p>\n<ul>\n<li>Using the `==` operator<\/li>\n<li>Using the `!=` operator<\/li>\n<li>Using the `<` operator<\/li>\n<li>Using the `>` operator<\/li>\n<li>Using the `<=` operator<\/li>\n<li>Using the `>=` operator<\/li>\n<\/ul>\n<p>Using the `==` operator<\/p>\n<p>The `==` operator compares two strings and returns `true` if the strings are equal, and `false` otherwise. To use the `==` operator, you can use the following syntax:<\/p>\n<p>c++<br \/>\nif (string1 == string2) {<br \/>\n  \/\/ The strings are equal<br \/>\n} else {<br \/>\n  \/\/ The strings are not equal<br \/>\n}<\/p>\n<p>Using the `!=` operator<\/p>\n<p>The `!=` operator compares two strings and returns `true` if the strings are not equal, and `false` otherwise<\/p>\n<p><b><b>Q: How do I loop through a string in C++?<\/b><\/b><\/p>\n<p>A: To loop through a string in C++, you can use the `for` loop. The syntax is as follows:<\/p>\n<p>c++<br \/>\nfor (int i = 0; i < string.length(); i++) {\n  \/\/ Do something with the character at index i\n}\n\n\nFor example, the following code prints each character in the string `\"hello\"`:\n\nc++\ninclude <iostream><\/p>\n<p>using namespace std;<\/p>\n<p>int main() {<br \/>\n  string str = &#8220;hello&#8221;;<\/p>\n<p>  for (int i = 0; i < str.length(); i++) {\n    cout << str[i] << endl;\n  }\n\n  return 0;\n}\n\n\n<b><b>Q: What is the difference between `for` and `foreach` loops in C++?<\/b><\/b><\/p>\n<p>A: The `for` loop is a general-purpose loop that can be used to iterate over any type of sequence. The `foreach` loop is a specialized loop that is specifically designed for iterating over collections of objects.<\/p>\n<p>The syntax of the `for` loop is as follows:<\/p>\n<p>c++<br \/>\nfor (int i = 0; i < n; i++) {\n  \/\/ Do something with i\n}\n\n\nThe syntax of the `foreach` loop is as follows:\n\nc++\nfor (auto item : collection) {\n  \/\/ Do something with item\n}\n\n\nThe main difference between the two loops is that the `foreach` loop automatically iterates over the elements of a collection, while the `for` loop requires you to specify the index of each element.\n\nIn general, the `foreach` loop is more concise and easier to use than the `for` loop. However, the `for` loop is more flexible, as it can be used to iterate over any type of sequence, not just collections of objects.\n\n<b><b>Q: How do I skip a character when looping through a string in C++?<\/b><\/b><\/p>\n<p>A: To skip a character when looping through a string in C++, you can use the `continue` statement. The `continue` statement tells the loop to skip the current iteration and continue with the next iteration.<\/p>\n<p>For example, the following code prints all of the characters in the string `&#8221;hello&#8221;` except for the letter `&#8217;o&#8217;`:<\/p>\n<p>c++<br \/>\ninclude <iostream><\/p>\n<p>using namespace std;<\/p>\n<p>int main() {<br \/>\n  string str = &#8220;hello&#8221;;<\/p>\n<p>  for (int i = 0; i < str.length(); i++) {\n    if (str[i] == 'o') {\n      continue;\n    }\n\n    cout << str[i] << endl;\n  }\n\n  return 0;\n}\n\n\n<b><b>Q: How do I reverse a string in C++?<\/b><\/b><\/p>\n<p>A: To reverse a string in C++, you can use the following algorithm:<\/p>\n<p>1. Create a new string of the same length as the original string.<br \/>\n2. Initialize a pointer to the beginning of the original string and a pointer to the end of the new string.<br \/>\n3. While the pointer to the original string is not at the end of the string:<br \/>\n    1. Copy the character at the pointer to the original string to the pointer to the new string.<br \/>\n    2. Move the pointer to the original string one character to the right.<br \/>\n    3. Move the pointer to the new string one character to the left.<br \/>\n4. The new string will now be the reverse of the original string.<\/p>\n<p>For example, the following code reverses the string `&#8221;hello&#8221;`:<\/p>\n<p>c++<br \/>\ninclude <iostream><\/p>\n<p>using namespace std;<\/p>\n<p>int main() {<br \/>\n  string str = &#8220;hello&#8221;;<br \/>\n  string reversedStr = &#8220;&#8221;;<\/p>\n<p>  for (int i = str.length() &#8211; 1; i >= 0; i&#8211;) {<br \/>\n    reversedStr += str[i];<br \/>\n  }<\/p>\n<p>  cout << \"The reversed string is: \" << reversedStr << endl;\n\n  return 0;\n}\n\n\n<b><b>Q: How do I check if a string contains a substring in C++?<\/b><\/b><\/p>\n<p>A: To check if a string contains a substring in C++, you can use the following methods:<\/p>\n<ul>\n<li>The `find()` method: The `find()` method returns the index of the first occurrence of the substring in the string. If the substring is not found, the `\n<\/p>\n<p>In this blog post, we have discussed how to loop through a string in C++. We have covered three different methods: using the for loop, the while loop, and the ranged-based for loop. We have also provided code examples for each method.<\/li>\n<\/ul>\n<p>We hope that this blog post has been helpful. If you have any questions or comments, please feel free to leave them below.<\/p>\n<p>Here are some key takeaways from this blog post:<\/p>\n<ul>\n<li>To loop through a string using the for loop, you can use the following syntax:<\/li>\n<\/ul>\n<p>for (int i = 0; i < string.length(); i++) {\n  \/\/ Do something with the character at index i\n}\n\n\n\n\n<ul>\n<li>To loop through a string using the while loop, you can use the following syntax:<\/li>\n<\/ul>\n<p>int i = 0;<br \/>\nwhile (i < string.length()) {\n  \/\/ Do something with the character at index i\n  i++;\n}\n\n\n\n\n<ul>\n<li>To loop through a string using the ranged-based for loop, you can use the following syntax:<\/li>\n<\/ul>\n<p>for (char c : string) {<br \/>\n  \/\/ Do something with the character c<br \/>\n}<\/p>\n<p>We encourage you to experiment with these different methods and find the one that works best for you.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Looping Through Strings in C++ Strings are a fundamental data type in C++, and they&#8217;re used to store sequences of characters. Looping through a string is a common task, and there are a few different ways to do it. In this article, we&#8217;ll take a look at the three most common methods for looping through&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"footnotes":""},"categories":[15],"tags":[],"class_list":["post-8520","post","type-post","status-publish","format-standard","hentry","category-how-to-guides"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to Loop Through a String in C++<\/title>\n<meta name=\"description\" content=\"Learn how to loop through a string in C++ with this easy-to-follow guide. Includes examples of different looping methods, such as for loops, while loops, and do-while loops.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/hatchjs.com\/looping-through-string-c\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Loop Through a String in C++\" \/>\n<meta property=\"og:description\" content=\"Learn how to loop through a string in C++ with this easy-to-follow guide. Includes examples of different looping methods, such as for loops, while loops, and do-while loops.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/hatchjs.com\/looping-through-string-c\/\" \/>\n<meta property=\"og:site_name\" content=\"HatchJS.com\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/marcusgreenwood\/\" \/>\n<meta property=\"article:published_time\" content=\"2023-12-25T20:43:09+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-01-05T16:02:48+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/hatchjs.com\/wp-content\/uploads\/2023\/12\/Hatch.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"675\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Tony Becker\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@inventur_es\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Tony Becker\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/hatchjs.com\\\/looping-through-string-c\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/hatchjs.com\\\/looping-through-string-c\\\/\"},\"author\":{\"name\":\"Tony Becker\",\"@id\":\"https:\\\/\\\/hatchjs.com\\\/#\\\/schema\\\/person\\\/0bb989e8d318f81bd8660b0f6b33c6a8\"},\"headline\":\"How to Loop Through a String in C++\",\"datePublished\":\"2023-12-25T20:43:09+00:00\",\"dateModified\":\"2024-01-05T16:02:48+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/hatchjs.com\\\/looping-through-string-c\\\/\"},\"wordCount\":170,\"articleSection\":[\"How To Guides\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/hatchjs.com\\\/looping-through-string-c\\\/\",\"url\":\"https:\\\/\\\/hatchjs.com\\\/looping-through-string-c\\\/\",\"name\":\"How to Loop Through a String in C++\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/hatchjs.com\\\/#website\"},\"datePublished\":\"2023-12-25T20:43:09+00:00\",\"dateModified\":\"2024-01-05T16:02:48+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/hatchjs.com\\\/#\\\/schema\\\/person\\\/0bb989e8d318f81bd8660b0f6b33c6a8\"},\"description\":\"Learn how to loop through a string in C++ with this easy-to-follow guide. Includes examples of different looping methods, such as for loops, while loops, and do-while loops.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/hatchjs.com\\\/looping-through-string-c\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/hatchjs.com\\\/looping-through-string-c\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/hatchjs.com\\\/looping-through-string-c\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/hatchjs.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Loop Through a String in C++\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/hatchjs.com\\\/#website\",\"url\":\"https:\\\/\\\/hatchjs.com\\\/\",\"name\":\"HatchJS.com\",\"description\":\"Cracking the Shell of Mystery\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/hatchjs.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/hatchjs.com\\\/#\\\/schema\\\/person\\\/0bb989e8d318f81bd8660b0f6b33c6a8\",\"name\":\"Tony Becker\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/50d58e00a32df2da0d0ca3199a0d87520e5fbade8058eb2748acf312c3516cc3?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/50d58e00a32df2da0d0ca3199a0d87520e5fbade8058eb2748acf312c3516cc3?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/50d58e00a32df2da0d0ca3199a0d87520e5fbade8058eb2748acf312c3516cc3?s=96&d=mm&r=g\",\"caption\":\"Tony Becker\"},\"sameAs\":[\"http:\\\/\\\/hatchjs.com\",\"https:\\\/\\\/www.facebook.com\\\/marcusgreenwood\\\/\",\"https:\\\/\\\/uk.linkedin.com\\\/in\\\/marcusgreenwood\",\"https:\\\/\\\/www.pinterest.com\\\/hatchjs\\\/\",\"https:\\\/\\\/x.com\\\/inventur_es\",\"https:\\\/\\\/www.youtube.com\\\/user\\\/hatchjs\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Loop Through a String in C++","description":"Learn how to loop through a string in C++ with this easy-to-follow guide. Includes examples of different looping methods, such as for loops, while loops, and do-while loops.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/hatchjs.com\/looping-through-string-c\/","og_locale":"en_US","og_type":"article","og_title":"How to Loop Through a String in C++","og_description":"Learn how to loop through a string in C++ with this easy-to-follow guide. Includes examples of different looping methods, such as for loops, while loops, and do-while loops.","og_url":"https:\/\/hatchjs.com\/looping-through-string-c\/","og_site_name":"HatchJS.com","article_author":"https:\/\/www.facebook.com\/marcusgreenwood\/","article_published_time":"2023-12-25T20:43:09+00:00","article_modified_time":"2024-01-05T16:02:48+00:00","og_image":[{"width":1200,"height":675,"url":"https:\/\/hatchjs.com\/wp-content\/uploads\/2023\/12\/Hatch.png","type":"image\/png"}],"author":"Tony Becker","twitter_card":"summary_large_image","twitter_creator":"@inventur_es","twitter_misc":{"Written by":"Tony Becker","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/hatchjs.com\/looping-through-string-c\/#article","isPartOf":{"@id":"https:\/\/hatchjs.com\/looping-through-string-c\/"},"author":{"name":"Tony Becker","@id":"https:\/\/hatchjs.com\/#\/schema\/person\/0bb989e8d318f81bd8660b0f6b33c6a8"},"headline":"How to Loop Through a String in C++","datePublished":"2023-12-25T20:43:09+00:00","dateModified":"2024-01-05T16:02:48+00:00","mainEntityOfPage":{"@id":"https:\/\/hatchjs.com\/looping-through-string-c\/"},"wordCount":170,"articleSection":["How To Guides"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/hatchjs.com\/looping-through-string-c\/","url":"https:\/\/hatchjs.com\/looping-through-string-c\/","name":"How to Loop Through a String in C++","isPartOf":{"@id":"https:\/\/hatchjs.com\/#website"},"datePublished":"2023-12-25T20:43:09+00:00","dateModified":"2024-01-05T16:02:48+00:00","author":{"@id":"https:\/\/hatchjs.com\/#\/schema\/person\/0bb989e8d318f81bd8660b0f6b33c6a8"},"description":"Learn how to loop through a string in C++ with this easy-to-follow guide. Includes examples of different looping methods, such as for loops, while loops, and do-while loops.","breadcrumb":{"@id":"https:\/\/hatchjs.com\/looping-through-string-c\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/hatchjs.com\/looping-through-string-c\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/hatchjs.com\/looping-through-string-c\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/hatchjs.com\/"},{"@type":"ListItem","position":2,"name":"How to Loop Through a String in C++"}]},{"@type":"WebSite","@id":"https:\/\/hatchjs.com\/#website","url":"https:\/\/hatchjs.com\/","name":"HatchJS.com","description":"Cracking the Shell of Mystery","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/hatchjs.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/hatchjs.com\/#\/schema\/person\/0bb989e8d318f81bd8660b0f6b33c6a8","name":"Tony Becker","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/50d58e00a32df2da0d0ca3199a0d87520e5fbade8058eb2748acf312c3516cc3?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/50d58e00a32df2da0d0ca3199a0d87520e5fbade8058eb2748acf312c3516cc3?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/50d58e00a32df2da0d0ca3199a0d87520e5fbade8058eb2748acf312c3516cc3?s=96&d=mm&r=g","caption":"Tony Becker"},"sameAs":["http:\/\/hatchjs.com","https:\/\/www.facebook.com\/marcusgreenwood\/","https:\/\/uk.linkedin.com\/in\/marcusgreenwood","https:\/\/www.pinterest.com\/hatchjs\/","https:\/\/x.com\/inventur_es","https:\/\/www.youtube.com\/user\/hatchjs"]}]}},"_links":{"self":[{"href":"https:\/\/hatchjs.com\/wp-json\/wp\/v2\/posts\/8520","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hatchjs.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hatchjs.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hatchjs.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hatchjs.com\/wp-json\/wp\/v2\/comments?post=8520"}],"version-history":[{"count":1,"href":"https:\/\/hatchjs.com\/wp-json\/wp\/v2\/posts\/8520\/revisions"}],"predecessor-version":[{"id":8521,"href":"https:\/\/hatchjs.com\/wp-json\/wp\/v2\/posts\/8520\/revisions\/8521"}],"wp:attachment":[{"href":"https:\/\/hatchjs.com\/wp-json\/wp\/v2\/media?parent=8520"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hatchjs.com\/wp-json\/wp\/v2\/categories?post=8520"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hatchjs.com\/wp-json\/wp\/v2\/tags?post=8520"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}