<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: uSay</title>
    <description>The latest articles on Forem by uSay (@usay).</description>
    <link>https://forem.com/usay</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1065684%2F0ee73745-8196-41c0-861e-06c40a93434a.png</url>
      <title>Forem: uSay</title>
      <link>https://forem.com/usay</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/usay"/>
    <language>en</language>
    <item>
      <title>Range-based for loop with strings</title>
      <dc:creator>uSay</dc:creator>
      <pubDate>Sat, 15 Apr 2023 19:39:32 +0000</pubDate>
      <link>https://forem.com/usay/range-based-for-loop-with-strings-3l05</link>
      <guid>https://forem.com/usay/range-based-for-loop-with-strings-3l05</guid>
      <description>&lt;p&gt;&lt;strong&gt;This is post just for myself as a memo.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I am confused when I wrote range-based for loop, directly putting string as a target.&lt;br&gt;
Putting string as the target of range-based for loop flashed into my mind when I practiced hashmap like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int cnt = 0;
bool flag = true;
  while(flag){
    for(char &amp;amp;e: "balloon"){
      map[e]--;
      if(map[e] &amp;lt; 0) flag = false;
      }
      if(flag) cnt++;
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;However, this while loop finished after the 'n'.&lt;br&gt;
I had no idea about this phenomenon.&lt;br&gt;
This is why, I tested and tried to confirm their movement.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int main(void){
    // Your code here!
    for(auto e: "TestStrings"){
        cout &amp;lt;&amp;lt; e &amp;lt;&amp;lt; ':';
        printf("%X ", e);
    }
    cout &amp;lt;&amp;lt; endl;
    string s = "TestStrings";
    for(auto &amp;amp;e: s){
        cout &amp;lt;&amp;lt; e &amp;lt;&amp;lt; ':';
        printf("%X ", e);
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code shows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// T:54 e:65 s:73 t:74 S:53 t:74 r:72 i:69 n:6E g:67 s:73 :0 
// T:54 e:65 s:73 t:74 S:53 t:74 r:72 i:69 n:6E g:67 s:73
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Conclusion: The former has a NULL at its end of the line.&lt;/p&gt;

</description>
      <category>cpp</category>
      <category>memo</category>
    </item>
  </channel>
</rss>
